Originally Posted by
SCRIPT_KITTEH
I wonder what will happen if I exceed the array length?
You are in the realm of undefined behaviour. It so happens that it "works" for you with the input that you tested with, but say, if you enter longer input, or if your program was more complex, or if you compile it on a different system, with a different compiler, or with different compiler flags, you might get some kind of error.
For example, I enter all the letters of the English alphabet, in lowercase, as the "name", and your program crashed for me. Or, I changed your program to:
Code:
#include <stdio.h>
int main(void) {
char greeting[] = "Hi";
char name[3];
printf("\nWhat's your name?\n");
scanf("%s", name);
printf("\n%s, %s.\n", greeting, name);
return 0;
}
Then entered "Benjamin", and got this output: