Skip to main content
'simplified' version created 'pl' with the incorrect data type
Source Link
Super Cat
  • 1.7k
  • 1
  • 19
  • 25
  • Arrays are interpreted as pointers to their first value - Using an array without any iteration returns the address of the first value
  • pl must be a reference because we cannot copy arrays
  • With arrays, when you add a number to the array object itself, it advances forward that many times and 'points' to the equivalent entry - If n is the number in question, then ia[n] is the same as *(ia+n) (We're dereferencing the address that's n 'entriesentries forward), and ia+n is the same as &ia[n] (We're getting the address of the that entry in the array).
int ia[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}; for (int n = 0, *pl;0; n != 3; ++n) plauto &pl = ia[n]; 
  • Arrays are interpreted as pointers to their first value - Using an array without any iteration returns the address of the first value
  • pl must be a reference because we cannot copy arrays
  • With arrays, when you add a number to the array object itself, it advances forward that many times and 'points' to the equivalent entry - If n is the number in question, then ia[n] is the same as *(ia+n) (We're dereferencing the address that's n 'entries forward), and ia+n is the same as &ia[n] (We're getting the address of the that entry in the array).
int ia[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}; for (int n = 0, *pl; n != 3; ++n) pl = ia[n]; 
  • Arrays are interpreted as pointers to their first value - Using an array without any iteration returns the address of the first value
  • pl must be a reference because we cannot copy arrays
  • With arrays, when you add a number to the array object itself, it advances forward that many times and 'points' to the equivalent entry - If n is the number in question, then ia[n] is the same as *(ia+n) (We're dereferencing the address that's n entries forward), and ia+n is the same as &ia[n] (We're getting the address of the that entry in the array).
int ia[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}; for (int n = 0; n != 3; ++n) auto &pl = ia[n]; 
deleted 326 characters in body
Source Link
Super Cat
  • 1.7k
  • 1
  • 19
  • 25
 int ia[3]ib[3] = {1,2,3}; // short for (auto pl : iaib) /* pl is ancout integer<< */pl; // long for (int n = 0;   for (auto in != ia[n]; ia+n < end(ia);3; ++n) /* pl is ancout integer<< */ib[n]; 
 int ia[3] = {1,2,3}; // short for (auto pl : ia) /* pl is an integer */ // long int n = 0;   for (auto i = ia[n]; ia+n < end(ia); ++n) /* pl is an integer */ 
 int ib[3] = {1,2,3}; // short for (auto pl : ib) cout << pl; // long for (int n = 0; n != 3; ++n) cout << ib[n]; 
deleted 326 characters in body
Source Link
Super Cat
  • 1.7k
  • 1
  • 19
  • 25

It's really just a simplified way to write this:

int ia[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}; for (int n = 0, *pl; n != 3; ++n) pl = ia[n]; 

It's really just a simplified way to write this:

int ia[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}; for (int n = 0, *pl; n != 3; ++n) pl = ia[n]; 
deleted 326 characters in body
Source Link
Super Cat
  • 1.7k
  • 1
  • 19
  • 25
Loading
Source Link
Super Cat
  • 1.7k
  • 1
  • 19
  • 25
Loading