I came across this block of code when studying for my class. It was in my professor's presentation and I thought it was an error, so out of pure curiosity, I tried to compile it. To my surprise, it's actually a valid code. I tried looking it up online but couldn't find a clear answer as to why exactly does it work.
int n, num;
scanf("%d", &n);
vector<int> arr;
arr.reserve(n);
while (n--)
scanf("%d", &num),
arr.push_back(num);
for (int i : arr) printf("%d ", i);
printf("\n");
I expected the while-loop to cause a compilation error, but it runs smoothly. Is it standard or was that introduced recently?