1

By mistake I wrote something like this:

int tab[2][4] = {{1, 2, 3}, {4, 5, 6}};
int c = tab[1, 2]; /* expect compilation failure */

I expect this syntax cause compilation failure (linux, gcc 4.7), but gcc warn and compile. What is the meaning of the second line? Is the behavior defined in the standard? I don't find answer in it.

Thank you.

choukette
  • 11
  • 2
  • 1
    It uses [the comma operator](https://en.cppreference.com/w/c/language/operator_other#Comma_operator). – Some programmer dude Feb 27 '19 at 11:25
  • 1
    C does not have the syntax `[a,b]` to index multi-dimensional arrays. C has however the comma operator which executes the expressions separated by the comma sequentially, yielding the last result as the result of the sequence. This means that your expression is equivalent to `tab[2]`. – Paul Ogilvie Feb 27 '19 at 11:26

0 Answers0