Thursday, July 12, 2007

Interesting C Program -9

Something weird in the output of the following program:


#include "stdio.h"
void main(void)
{
int c = 10;
printf("%d\n",c);
printf("%d\n",sizeof(++c));
printf("%d\n",c);
}

The output will be:
10
4
10
++c inside sizeof function is ignored.
Why?


The answer goes like this:
The input argument to sizeof function is datatype and not data. So the datatype of ++i will be considered instead of data ++i. So it will not be incremented.

No comments:

Search Google

Books that I refer to...

  • The Complete Reference C, Fourth Edition
  • The C Programming Language