#include
int main()
{
char s[2]=\"a\";
s[1]=\'b\';s[2]=\'c\';s[3]=\'d\';s[5]=\'e\';
printf(\"%s $%c$\",s,s[4]);
return 0;
}
\a
if I remebember correct so it isn't necessary that something is actually printed on the screen. It might have been a sound that you never heard.Accessing out of bound of an array is undefined behaviour. Just an example same code's output on my system is abcd(e▒x $($
string of length 8 is because of lack of NULL terminator and character (
between $
is garbage value of s[4]
.
You are writing/reading outside of the bounds of the array, this is simply undefined behavior you can not make any predictions about what the program will do.