#include<stdio.h>
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;
}
1.When I run this program in C (gcc-4.7.2) I expected Runtime Error because of the missing Null Character ('\0').
2.If still the program compiles and executes successfully ,since s[4] has not been initialised,I expected some garbage value at that place..but here also I was wrong.
The output of the above program is: abcde $$ There is no character between the two $(dollor) which indicates printf skips s[4]. here is a ideone link for the same: http://ideone.com/UUQxb2
Explain the reason for this behaviour (output) ?