P
Pete
Quick question: What does ary[i,j] return in C/C++?
I know that C/C++ does not have two-dimensional arrays, thus
ary[i,j] is not valid notation. Instead I should use ary[j]
. But.
But I was this past week using g++, the GNU C++ compiler, running a
default install of Red Hat 9 (I don't know the exact compiler version,
but you get the gist). I made the mistake of using ary[i,j] in
my code, and the program *COMPILED WITHOUT ERRORS*. The resulting
behavior at run-time was, of course, wrong. Why? Why did it compile
in the first place?
What does ary[i,j] mean? It compiles, so it must mean something...
As an example, let's start with this:
//-------------------------
//
// BEGIN FAKEY-CODE
int ary[5][12];
int i = 4;
int j = 7;
cout << &(ary[j]) << endl;
cout << &(ary[i,j]) << endl;
// END FAKEY-CODE
//
//-------------------------
Curious,
Pete
I know that C/C++ does not have two-dimensional arrays, thus
ary[i,j] is not valid notation. Instead I should use ary[j]
. But.
But I was this past week using g++, the GNU C++ compiler, running a
default install of Red Hat 9 (I don't know the exact compiler version,
but you get the gist). I made the mistake of using ary[i,j] in
my code, and the program *COMPILED WITHOUT ERRORS*. The resulting
behavior at run-time was, of course, wrong. Why? Why did it compile
in the first place?
What does ary[i,j] mean? It compiles, so it must mean something...
As an example, let's start with this:
//-------------------------
//
// BEGIN FAKEY-CODE
int ary[5][12];
int i = 4;
int j = 7;
cout << &(ary[j]) << endl;
cout << &(ary[i,j]) << endl;
// END FAKEY-CODE
//
//-------------------------
Curious,
Pete