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?

2

1 Answer 1

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]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.