Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the [x,y] symbol mean in a multidimensional array access? [duplicate]

I'm studying C and I came across the code below. The printed results are always the same for all the printf calls.

What does [x,y] mean? A memory address or something else?

printf("%d ", array[0,0]);
printf("%d ", array[1,0]);
printf("%d ", array[2,0]);
like image 838
A.Sim Avatar asked Dec 02 '22 09:12

A.Sim


1 Answers

The comma operator in c returns the second argument. So 0,0, 1,0, and 2,0 all evaluate to 0, so its no wonder that all the printf statements print the same result. If you want to refer to an element in a two-dimensional array by its indexes, you need to use two sets of square bracket. E.g., array[1][0].

like image 96
Mureinik Avatar answered Dec 04 '22 08:12

Mureinik