Post-increment operator in C -


i casually coding when wrote c code:

#include <stdio.h> int main() {     int i;     = 10;     printf("i : %d\n",i);     printf("sizeof(i++) is: %d\n",sizeof(i++));     printf("i : %d\n",i);     return 0; } 

and when ran code, result is,

i : 10 sizeof(i++) is: 4 : 10 

i baffled result expected i++ inside sizeof operator have incremented i. seems not. out of curiosity wrote following program:

#include <stdio.h> int  add(int i) {     int = + 2;     return 4; } int main() {     int i;     = 10;     printf("i : %d\n",i);     printf("sizeof(i++) is: %d\n",add(i++));     printf("i : %d\n",i);     return 0; } 

for program, output is:

i : 10 sizeof(i++) is: 4 : 11 

now i'm more , more baffled.

sorry if noob question (which am) don't understand how google such problem!

why value of different in these 2 programs? please help!

sizeof() isn't runtime function. gives size of variable or size of return value of function.

so in first example, you're getting size of result value of post-increment operator on integer integer... 4 bytes.

in example you're printing return value of method returns 4, , variable increments, , print 11.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -