void main(){
char s[10];
s[1]='a';
s[6]='4';
for(int i=0;i<10;i++)
printf("%c",s[i]);
}
I have this simple program. It gives the following output:
@aO 4
If I change the above code to:
void main(){
char s[10];
s[1]='a';
s[6]='4';
for(int i=0;i<10;i++)
printf("%c",s[i]);
printf("\n");
for(int i=0;i<10;i++)
printf("%c",s[i]);
}
Output changes to:
@a@ 4
@a@ 4
There are actually 2 cubes containing 4 numbers (1 number in each quadrant of the cube) between 'a' and the '@' after a but for some reason they are not showing.Please try the above codes in code blocks if I do not make sense to you.
I was expecting the output to be a 4 by the first code.Why is it not so? Also, why did the output change when I added more code? I was expecting the output to be:
a 4
a 4
J.2 Undefined Behaviorit is writtenthe value of an object with automatic storage duration is used while it is indeterminate (6.2.4, 6.7.9, 6.8).