Question: Given the following code:

```
#include<iostream>
int main(){
  char container[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g'};
  for(char* cptr = container; *cptr != 0; cptr++)
    std::cout << *cptr << std::endl;
  return 0;
}

```

It prints these characters in sequence each time I execute it. I cannot understand why the loop would terminate since I have not explicitly specified any null terminator at the end of the container array. Please help.

Answer: 
It's just luck, really.

It happens that the area of memory corresponding to `container[7]` is 0, so you're getting lucky.

Exceeding the bounds of your array is undefined behavior. In your case, it just happens to be the behavior you were hoping for, but you can't rely on that.
You're running off the end of the array which invokes undefined behavior. One possible undefined behavior is that it works in a seemingly reasonable way. In this case probably what's happening is that the undefined behavior is padding your array with zeros.