Is this valid/what would this do (C):
int *p;
p=0;
p++;
printf("%d",p);
Interview Answers
Anonymous
22 Jun 2013
"4". Increment the address by one unit of integer, which is from 0 to 4.
1
Anonymous
16 Jul 2013
This should led to a compiler warning. "p" is unsigned as it is address not value, so "%d" is not valid. Anyway, it will output "sizeof(int)", you cannot rely on "4", because it did not say 32bit or 64bit or even 16bit system.
1
Anonymous
20 Dec 2014
This should led to a comiler warning: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int*’ [-Wformat=]
printf("%d\n", p);
Anonymous
14 Jul 2013
...not really. printf will print an integer found in the second integer position. note that p=0 is different than *p=0