Hey Pradeep,
I don't find any strange behavior in the code you have given here,
#include "stdio.h"
int main() {
int i = 0, j = 0;
j = sizeof(++i);
printf("i = %d\nj = %d\n", i, j);
return 0;
}
But i can give you the explanation for the output, first you have declared and assigned two variable i = 0 and j = 0 , then you have used j = sizeof (++i)
when you use the print f to print the value of i and j , the value of i will be 0 only as you have assigned the value of i=0 so it will always yield 0 and the value of j will be 4 as the size of integer is 4 bytes.
I think the question your trying to ask is, we have used ++i and so the value of i should be incremented from 0 to 1. right???
If that was your question here is the answer, see by using j = sizeof(++i) will not change the value of i (because we are assigning the value only to j and not i ) so we have to include something like this in the code, i = ++i , so it will yield the value of i as 1.
and more over sizeof() is only used for returning the size of a variable.
#include <stdio.h>
int main() {
int i = 0, j = 0;
j = sizeof(++i);
i = ++i;
printf("i = %d\nj = %d\n", i, j);
return 0;
}
Hope that's the answer your expecting buddy!!! ok let me know if I am wrong or can you make the question clear so that i can give it another try!! 😀
Regards,
Arvind (slashfear) 😉