I'm a beginner in C++ and trying to get my head around every new concept I come across by writting as many various little programs (programmlets) as possible. So I've just concocted the following piece of code:
#include <iostream>
using namespace std;
int main(){
int inumbers[] = {1 ,2 , 3, 4, 5};
int *p;
int i;
p = inumbers;
for(i = 0; p[i]; i++) cout << p[i] << '\n';
return 0;
}
And I fail to understand a seemingly simple thing: how does a compiler "know" when to stop incrementing the loop variable "i"? Surprisingly, the code does work the way it was supposed to.