Why does the following program runs and works correctly
=============== =============== ===============
#include <stdio.h>
#include <string.h>
char a = 'a'; / * One byte*/
int main(int argc, char **argv)
{
printf("%s", &a);
/* Prints a */
/* Undefined behaviour on a*/
strcpy (&a, "HELLOOOOOOOOOO OOOOOOOOOOOOOOO OOOO");
printf("%s", &a);
/* Should not print HELOOOO...... correctly */
/*i Think it must print H */
return 0;
}
=============== =============== =============
I have copied a full string into a char and prints that string
correctly ?
=============== =============== ===============
#include <stdio.h>
#include <string.h>
char a = 'a'; / * One byte*/
int main(int argc, char **argv)
{
printf("%s", &a);
/* Prints a */
/* Undefined behaviour on a*/
strcpy (&a, "HELLOOOOOOOOOO OOOOOOOOOOOOOOO OOOO");
printf("%s", &a);
/* Should not print HELOOOO...... correctly */
/*i Think it must print H */
return 0;
}
=============== =============== =============
I have copied a full string into a char and prints that string
correctly ?
Comment