Modify operators in C Language

Modify Operators in C Language :  Modify operators also called Unary operators or Increment and Decrement operators. This Post explain clearly how to evaluate expressions including modify operators.


 

Modifying operators:

  • These operators also called Unary operators(performs operation on single operand).
  • Divided into Increment and Decrement operators.
  • Increment operators increases the value of a variable by 1.
  • Decrement operators decreases the value of a variable by 1.

 

Increment operators is of two types
1) pre-increment
2) post-increment

 

Decrement operators is of two types
1) pre-decrement
2) post-decrement

 

 

Evaluation steps of expression which includes modifying operators and arithmetic operators:

 

 #include<stdio.h>
    main()
    {
        int a=10,b;
        b = ++a;
        printf(“%d,%d”,a,b);
    }    

 

#include<stdio.h>
    main()
    {
        int a=10,b;
        b = a++;
        printf(“%d,%d”,a,b);
    }

 

#include<stdio.h>
    main()
    {
        int x=10,y=20,z;
        z = x++ * –y ;
        printf(“%d,%d,%d”,x,y,z);
    } 

 

#include<stdio.h>
    main()
    {
        int x=3,y=7,z;
        z = ++x * y– ;
        x = y– + ++z ;
        y = z– + x++ ;
        printf(“%d,%d,%d”,x,y,z);
    }

 

#include<stdio.h>
    main()
    {
        int x=5,y=4,z;
        z = x– – ++y ;
        x = z– + –y ;
        z = –x – ++y ;
        z = ++y + –x ;
        printf(“%d,%d,%d”,x,y,z);
    }

 

#include<stdio.h>
    main()
    {
        int a =5;
        a = a++ +  ++a ;
        printf(“a : %d\n”,a);
    } 

 

#include<stdio.h>
    main()
    {
        int a=4,b=5;
        b = a++ + a–;
        a = ++b + b–;
        printf(“%d,%d”,a,b);
    }

 

#include<stdio.h>
    main()
    {
        int a=6,b=3;
        b = a– + a– + a++;
        b = b– ;
        a = a++ + ++b;
        printf(“%d,%d”,a,b);
    }

 

#include<stdio.h>
    main()
    {
        int a=5;
        printf(“%d,%d,%d”,++a, a++ , –a);
    }

 

#include<stdio.h>
    main()
    {
        int a=3,b=5;
        printf(“%d,%d,%d”, a++ – ++b , –a + b– , ++a-b–);
    }

 

Note : C language is not space consistent, for example…
a = 5;
a = a+++a; 

 

Above expression can be written as…
a = a + ++a  ;     or     a = a++ + a ;

 

As ++ having higher prior than +, it treats as follows…
     a = a++ + a ;  —> Hence output is  11.

Share this