Question: I'm learning C and am currently experimenting with storing strings in variables. I put together the following to try different stuff.

```
#include <stdio.h>
int main() {
    char *name = "Tristan";
    char today[] = "January 1st, 2016";
    char newyear[] = {'H','a','p','p','y',' ','N','e','w',' ','Y','e','a','r','!','\n'};
    printf("Hello world!\n");
    printf("My name is %s.\n", name);
    printf("Today is: %s.\n", today);
    printf(newyear);
    return 0;
}

```

After compiling this code and running it, I get the following results:

```
Hello world!
My name is Tristan.
Today is: January 1st, 2016.
Happy New Year!
January 1st, 2016

```

Now this is pretty much what I would expect, by why would "January 1st, 2016" get printed out again at the end of the program's output?

If I take the "\n" out of the "newyear" array, it will not do this.

Would someone please explain why this is?

Answer: 
`newyear` misses a trailing null byte, so `printf`ing it is undefined behavior.  

Only string literals implicitly append a null byte. You explicitly initialize every character, so **no null byte is appended**.

Undefined behavior means that something the standard does not define in this occasion will happen. That includes nothing happening, you bursting into tears, or, yes, printing some string twice.

Just add an additional character, i.e., a null byte to the array to resolve the problem:

```
char newyear[] = {'H','a','p','p','y',' ','N','e','w',' ','Y','e','a','r','!','\n', '\0'};

```

---

**Note** that no sane person initializes an automatic `char` array with a string like that. Just stick to string literals! (I think you did it just for learning purposes, though.)
Remember that strings in C are terminated by the special `'\0'` character.

Not having this terminator at the end of data that is treated as a string will lead to *undefined behavior* as the string functions pass the end of the data searching for the terminator.