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: 
First, the code you posted has a horrible bug: `cptr != 0` should be `*cptr != 0`. You should be checking to see if the *character* at the given address is null, not if the pointer itself is null.

The other answers and comments are correct. The only reason you're getting the correct output is because there happens to be some zeroed memory right at the end of your container array. Putting the `container` array inside a struct will help to eliminate the extra padding the compiler might otherwise insert:

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

```

If you run this version you'll see your array `'a'`–`'g'` printed, then it will run over into the second array and print `'A'`–`'Z'` before hitting the null at the end of that string.
You are evoking Undefined Behavior. Undefined Behavior means, "anything can happen," which includes, sometimes, exactly what you want to happen. That's what's happening here. 

The reason why you're invoking Undefined Behavior is because you are reading from uninitialized memory, when you access the element one-past-the-end of `container`.