6

I have read this post. However, I could not get the meaning for the following declaration.

Lets say I declare this:

Declaration 1:    int jimmy [HEIGHT][WIDTH];

   Accessing 1:   jimmy[n][m]

Declaration 2: int jimmy [HEIGHT * WIDTH];


 Accessing 2:  jimmy[n*WIDTH+m]

Declaration 1 and accessing 1, and Declaration 2 and accessing 2 are same src.

However, what is the meaning jimmy[n,m]? I wrote the code it gives me address. Couldnt get any useful info. Can some one say what does it mean?

Community
  • 1
  • 1
  • 2
    See also: [wiki](https://en.wikipedia.org/wiki/Comma_operator) [cppref](http://en.cppreference.com/w/cpp/language/operator_other#Built-in_comma_operator) – Ivan Aksamentov - Drop Mar 29 '16 at 03:56
  • [How does the Comma Operator work](http://stackoverflow.com/q/54142/995714), [What is the proper use of the comma operator?](http://stackoverflow.com/q/17902992/995714), [When to Overload the Comma Operator?](http://stackoverflow.com/q/5602112/995714) – phuclv Mar 29 '16 at 04:21

1 Answers1

10

C++ has a comma operator which evaluates the thing on the left, discards the return value, and then evaluates to the thing on the right.

You could write (see http://ideone.com/hpQxWI)

int i = (1, 2, 3, 4);
std::cout << i;

and you would print out 4.

So

jimmy[n,m]

means

jimmy[m]
kfsone
  • 23,617
  • 2
  • 42
  • 74