Shorthand operator Example in C

C has two types of shorthand operators
  1. Shorthand Assignment operators
  2. Increment and Decrement operators

Shorthand Assignment operators

C has set of shorthand assignment operators of the form

    v op = exp;     
where v is variable op can be any arithmetic operator and exp is an expression.
The operator  op=  is known as the shorthand assignment operator. 

Lets understands, how it can be used!

The assignment statement
                              v op = exp;  is equivalent of  v = v + exp;

            It means x+=5; statement is equivalent of x=x+5;

Advantages of shorthand assignment operator
  1. The statement is more concise and easier to read.
  2. Saves time, no need to write again.
  3. The statement is more efficient.

commonly used shorthand assignment operator
commonly used shorthand assignment operator

Increment and Decrement operators
++ and -- are two very useful shorthand increment and decrement operators, ++ adds one to the operand while -- subtracts by one. Both are unary operators and follows following syntax.

PreIncrement/PreDecrement    OR PostIncrement/PostDecrement
++a;           OR         a++;
--a;            OR          a--;   

Pre means Add or Subtract by one immediately in operand.where as Post means Add or Subtract by one in very next appearance of operand in execution of statement.

Example of Increment and Decrement operators

Example of Increment and Decrement operators