Minhas Kamal
Minhas Kamal

Reputation: 22156

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?

Upvotes: 1

Views: 303

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272537

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.

Upvotes: 7

Related Questions