6. Introduction to c++: Operators, Precedence of operators :: Videos



Description:


What are we going to learn today?

 

  • Assignment operator(=):
    • Assign a value to variable.
    • Examples:
      • x=23;
      • y=x+53;
      • a=b=c=5;
  • Arithmetic operators(+,-,*,/,%):
    • + is addition, - is subtraction, * multiplication, / is division and % is modulo.
  • Compound assignment(+=,-=,*=……..):
    • Changing the value of a variable, using the current value stored in the same variable, compound assignment become useful
    • Examples:
      • a+=5 is same as a = a+5;
      • a-=5 is same as a = a-5
  • Increment and decrement(++, --):
    • ++:  Increment the value in variable by one unit
    • --: Decrement the value stored in variable by one unit
    • Examples:
      • a++ same as a = a + 1;
      • a-- same as a = a - 1;
  • Relational and equality(==, !=, >, <. >=, <=):
    • == Equal to? (not same as ‘=‘)
    • != Not equal to?
    • > greater than?
    • < smaller than?
    • >= greater than or equal to?
    • <= smaller than or equal to?
    • Example:
      • (23==53) is returned as false
  • Logical(!, &&, ||):
    • && and || are used to obtain a relational result between two expressions.
      • && corresponds to boolean logic AND
      • || corresponds to boolean logic OR
    • ! Corresponds to boolean logic NOT
  • Conditional(?:):
    • Evaluates an expression and returns true or false.
    • Example:
      • (7>5)?10:20; Will return 20 because 7 is greater than 5.
  • Comma operator(,):
    • Used when two or more expressions is included where only one is expected
  • Bitwise operator(&, |, ^, ~, <<, >>):
    • Used only when working with bits of data on low level.
    • & is bitwise AND
    • | is bitwise OR
    • ^ is bitwise XOR
    • ~ is bitwise NOT
    • << shift left (SHL)
    • >> shift right (SHR)
  • sizeof():
    • •Return size in bytes for a data type or variable itself.
    • Example: sizeof(char) will return 1 because char takes one byte of data in memory.
  • Precedence:
    • Order in which the operators are performed according to the priority. Priority order is defined for each operators.
    • Basic levels:
      • Level 1 is :: (called scope)
      • Level 2: () or []
      • Level 3: ++, --
      • Level 4: Type casting (type)
      • Level 5: * / % (Goes from left to right)
      • Level 6: +, - (Left to right)
      • Level 7: <, >, <=, >= relational (left to right)
      • Level 8: ==, !=
      • Level 9: bitwise operators
      • Level 10: && Logical AND (left to right)
      • Level 11: || Logical OR (left to right)
      • Level 12: ?: conditional (right to left)
      • Level 13: =, /= … Assignment operators (Right to left)
      • Level 14: comma(,) left to right


Head over to the resources section to get the powerpoint that is shown in the video.

 


Comments:

Please login to post your thoughts!
 

There are no commnets yet!
 

Login

Username:
Password:
Don't have an account?
Register here
Register

Subscribe Youtube



Network DigitalStage.org


Some interesting stuffs