I have the following code:
char buf[10];
strcpy(buf, "This is a string longer than way longer than ten characters.");
printf("%s\n", buf);
I know that the second line will result in a segfault as I'm writing past the length of the array buf, as I get the following:
./a.out
This is a string longer than way longer than ten characters.
Segmentation fault (core dumped)
How come the printf command is executed as strcpy gives a segfault? I ran without the print statement and I get only a segfault.