*Edit: Actually the language used in the standard in the above link is quite confusing to me in this regard, and there seems to be a lot of back-and-forth discussion between this, especially regarding ANSI C vs C++. I now don't think it's technically legal. It might be de facto legal, but I would avoid the &arr[len] construct and just replace it with arr + len... (or better yet, avoid using pointers in this manner and just use a regular int for loop!!)
Legal, but unnecessary pointer arithmetic:
1 2 3 4 5 6 7 8 9 10
#include<iostream>
usingnamespace std;
int main()
{
int *p;
constint len=20;
int arr[len];
for(p=arr;p<arr+len;p++)
*p=0;
}
Much more clear:
1 2 3 4 5 6 7 8 9
#include<iostream>
usingnamespace std;
int main()
{
constint len=20;
int arr[len];
for(int i = 0; i < len; i++)
arr[i] = 0;
}