T
Timothee Groleau
Hi,
Is it defined in C++ that 2 arrays of the same type defined one after the
other are contiguous in memory?
like saying:
int a1[10];
int a2[10];
implies (a1 + 10 == a2)?
Thinking in C++ seems to imply so but I'm not finding it to be true with GCC
3.3.6 .
For example, check the exercise 18 of chapter 3 of TIC++ second edition. in
my case with GCC 3.3.6, I get this:
================
#include <iostream>
using namespace std;
int main()
{
int a1[10];
int a2[10];
cout << a1 << endl;
cout << a2 << endl;
cout << (a2 - a1) << endl;
}
================
output:
0xbfb9c0f0
0xbfb9c0c0
-12
================
What gives?
Thanks,
Tim.
Is it defined in C++ that 2 arrays of the same type defined one after the
other are contiguous in memory?
like saying:
int a1[10];
int a2[10];
implies (a1 + 10 == a2)?
Thinking in C++ seems to imply so but I'm not finding it to be true with GCC
3.3.6 .
For example, check the exercise 18 of chapter 3 of TIC++ second edition. in
my case with GCC 3.3.6, I get this:
================
#include <iostream>
using namespace std;
int main()
{
int a1[10];
int a2[10];
cout << a1 << endl;
cout << a2 << endl;
cout << (a2 - a1) << endl;
}
================
output:
0xbfb9c0f0
0xbfb9c0c0
-12
================
What gives?
Thanks,
Tim.