0

This funny thing happened when I make a mistake .

I what write :

int i; i = 1;

but it is

int i ;i = 1 ,23;(I guess sometime I click the middle button of my mouse) .

Then I compiled the program by gcc and it went through without any warning or error!

And after I notice that . I try int i = 1,23; , and now the compile give a error:

error: expected identifier or ‘(’ before numeric constant

So ,Why the first time compile suceessful ?

And why it give me a error the second time?

What exactly ", 23" means?

Thanks in advance.

Lidong Guo
  • 2,817
  • 2
  • 19
  • 31
  • Also, [initialization is not assignment](http://stackoverflow.com/questions/16217839/is-there-a-difference-between-initializing-a-variable-and-assigning-it-a-value-i). –  Aug 07 '13 at 11:15
  • @H2CO3 What the first link mean? I go and only see **You see it used in for loop statements, but it's legal syntax anywhere. What uses have you found for it elsewhere, if any?** – Lidong Guo Aug 07 '13 at 11:18
  • 1
    @LidongGuo: You have to read the answers. – Felix Kling Aug 07 '13 at 11:19
  • 2
    @LidongGuo You run into the comma operator. `i = 1, 23` is the same as `(i = 1)` since the expression `23` has no side effects. –  Aug 07 '13 at 11:20
  • @H2CO3 Nope .I print i and i is 1 not 23! – Lidong Guo Aug 07 '13 at 11:23
  • If it helps, the precedence of `=` over `,` is the source of relatively many mistakes (among those foolish enough to use the comma operator at all): http://blog.frama-c.com/index.php?post/2012/12/18/zlib-one-comma-misused – Pascal Cuoq Aug 07 '13 at 12:36

0 Answers0