C Program : Increment and Decrement Operators?


Write a C Program to explain Increment and Decrement Operators?



 /* It explain post - increment & pre - increment and post - decrement & pre - decrement operators */

 #include < stdio.h >
  main()
   {

     int a, b, c, d;
     clrscr();
     printf("Enter two integer values a and b : ");
     scanf("%d %d ", &a, &b);

     printf("Following are the results of increment and decrement operators : \n");

     c = a++;
     printf("The values of c and a after c = a++ are %d and %d \n", c, a);

     c = ++b;
     printf("The values of c and b after c = ++b are %d and %d \n", c, b);

     d = a--;
     printf("The values of d and a after d = a-- are %d and %d \n", d, a);

     d = --b;
     printf("The values of d and b after c = --b are %d and %d \n", d, b);
     
     getch();
     
   }



Input : Enter two integer values a and b : 5 6

Output :
The values of c and a after c = a++ are 5 and 6
The values of c and a after c = ++b are 7 and 7
The values of d and a after d = a-- are 6 and 5
The values of d and b after d = --b are 6 and 6


0 Komentar untuk "C Program : Increment and Decrement Operators?"

Back To Top