+ 1
It was a decision by the designer of the C language (Dennis Ritchie), and C++ inherited it from C. On the plus side it does allow you to iterate over arrays in 'array index' syntax or 'pointer increment' syntax i.e; the following 2 loops are exactly equal: int z, arr[4] = {1,3,5,9}; for(int i = 0; i < 4; i++) z = arr[i]; for(int i = 0; i < 4; i++) z = *(arr+i); My guess for the rationale for this is efficiency i.e. when passing an array as a function argument this is kind of implicit 'pass by reference' semantics rather than implicit 'pass by value' semantics. But it does have its downside too - the designer of the D language (Walter Bright) considers this the biggest mistake in C - see http://www.drdobbs.com/architecture-and-design/cs-biggest-mistake/228701625 And C++, because of backwards compatibility reasons, is stuck with it as well!
3rd Feb 2017, 3:28 PM
Ettienne Gilbert
Ettienne Gilbert - avatar