#include<stdio.h>
void main()
{
int i;
char str[4] = "f4dfkjfj";
char str2[3] = "987";
char str3[2] = {'j','j','\0'};
//printf("%c\n",str[1]);
//printf("%c\n",1[str]);
puts(str);
puts(str2);
puts(str3);
}
Output observation:
- Printing
str2
prints the contents from bothstr2
andstr
. - Printing
str3
printsstr3
,str2
andstr
.
Why this behaviour while printing the not nul ended string, which is concatenated with strings previously defined until "\0" character is encountered by the puts() function (this function prints till it encounters a nul )?
(Note: I deliberately initialised them with too long initializer strings)