Yes, this is overflowing buffers on the stack.
The firstName
input did overflow into surName
. But you then changed surName
when you input that, and it overwrote the characters with Example
.
Because you overflowed firstName
, there is no null-terminator on the string, so it looks like firstName
is longer than it actually is. It then had the "end" of it overwritten (because those bytes belonged to another variable).
This is actually undefined behaviour. You don't know where the compiler will put your buffers in the stack.
To prevent overflowing your buffers, you should use fgets
to read strings, not scanf
:
fgets( firstName, 21, stdin );