Search code examples
clanguage-features

In C, why this statement- 'i = 5i' compiles & sets 'i' to zero?


In GCC the following C code compiles correctly-

int i = 7;
i = 5i;
printf("%d", i);

And prints- 0.

The statement i = 5i clearly makes no sense. Then why on earth the code does not give any compilation error? And why i becomes 0?


Solution

  • This is a GCC extension for representing the imaginary component of complex numbers.

    The compiler complains if you compile with -pedantic and -Werror: http://ideone.com/PMlZr5.