-1
main()
{
    int x[0];
    scanf("%s",x);
   printf("%s",x);
} 

Why this program not show any error when I input qwerty79 and this program give me output qwerty79?

  • 2
    The code declares an array with a “zero size”. Then accesses it in an manner of Undefined Behavior - this is a classical buffer overflow that “didn’t crash the program” (when compiled with a particular compiler and run with a particular runtime). It’s either luck or a curse.. – user2864740 Jan 20 '19 at 05:59

1 Answers1

-3

In this you declare array of int x with 0 members means their no memory space allocated for an array and their is no memory location name x.So , their is no type checking when you are entered string in integer and one another reason is that compiler only know that there is some variable x but that type is not known because their is no memory allocation of x.So,your program not given any error.For detail info you must read compilation process state theory which is a part of the Compiler Design Subject.