1.

Can you differentiate between “var++” and “++var”?

Answer»

EXPRESSIONS “var++” and “++var” are used for incrementing the value of the “var” variable.

“var++” will first give the evaluation of expression and then its value will be INCREMENTED by 1, thus it is CALLED as post-incrementation of a variable. “++var” will increment the value of the variable by one and then the evaluation of the expression will take place, thus it is called pre-incrementation of a variable.
Example:

/* C program to demonstrate the difference between var++ and ++var */ #INCLUDE<stdio.h> int main() { int x,y; x=7, y=1; printf("%d %d\n", x++, x); //will generate 7, 8 as output printf("%d %d", ++y, y); //will generate 2, 2 as output }


Discussion

No Comment Found