* foo is an array with 8 elements * bar is an array with 4 elements, and points to foo[4] * thus: bar[0] = foo[4] bar[1] = foo[5] bar[2] = foo[6] bar[4] = foo[7]
Pointers kind of make my brain go "duuuuuuuuuuuuuh...." ^^
Posted 03 June 2007 - 12:37 PM
* foo is an array with 8 elements * bar is an array with 4 elements, and points to foo[4] * thus: bar[0] = foo[4] bar[1] = foo[5] bar[2] = foo[6] bar[4] = foo[7]
Posted 03 June 2007 - 01:55 PM
// Array and associated pointer int myarray[8]; int *myinteriorpointer; // Now, have the pointer point to the 4th (zero based!) array element myinteriorpointer = &myarray[3]; // Is equivalent to = myarray + 3; // Now the following line pairs are semantically equivalent myarray[3] = 100; myinteriorpointer[0] = 100; myarray[5] = 1043; myinteriorpointer[2] = 1043; // You still can exceed the array "range" ! Both of these (should) crash. myarray[10] = 500; myinteriorpoiter[7] = 500;
Posted 04 June 2007 - 11:03 AM
int *bar[4]; int foo[8];
bar[0] = &foo[4]; bar[1] = &foo[5]; bar[2] = &foo[6]; bar[3] = &foo[7];
*bar[1] = 42; // Equivalent to foo[5] = 42;
Posted 04 June 2007 - 01:59 PM
poita said:
int foo[8]; int (&bar)[4] = reinterpret_cast<int(&)[4]>(foo[4]);
0 members, 1 guests, 0 anonymous users