Pre increment and Pre decrement Operator in C
Introduction:
We have discussed the increment operators in our previous article, Here is another example to demonstrate the functionality of the Pre increment and Pre decrement operators in the C Language.
Program to demonistrate Pre Increment and Pre Decrement :
1 2 3 4 5 6 7 8 9 10 11 12 |
/*Prefix increment Pre decrement*/ #include<stdio.h> int main(void) { int x=8; printf("x=%d \n",x); printf("x=%d \n",++x); /*Prefix increment*/ printf("x=%d \n",x); printf("x=%d \n",--x); /*Prefix decrement*/ printf("x=%d \n",x); return 0; } |
Pre Increment and Pre Decrement Program Output:
We saved the program as the increment.c
We are going to use the GNU GCC compiler to compile the program under the Ubuntu Linux system. Which generates the executable file named a.out. To Run the program use the ./a.out command on the terminal.
1 2 3 4 5 6 7 8 |
venkey@venkey$ gcc increment.c venkey@venkey$ ./a.out x=8 x=9 x=9 x=8 x=8 venkey@venkey$ |
Related C-Language Articles:
- Start Here – Step by step tutorials to Learn C programming Online with Example Programs – SillyCodes
- Increment Operators in C | Pre increment and Post Increment operators in C Language (sillycodes.com)
1 Response
[…] C Program to understand Pre increment and Pre decrement Operators […]