-6

I have just tried to know the output without supplying the variable instead just %d and there is no error in compiling the program but i wonder how the output displayed like below.

#include <stdio.h>

int main()
{
    printf("%d");    
    return 0;
}

The output became 7288368

LihO
  • 41,190
  • 11
  • 99
  • 167

1 Answers1

0

"why formatting input output requires variable to be supplied?"

Because the implementation of printf demands so. From the manual page of printf:

"Each conversion specification is introduced by the character %, and ends with a conversion specifier... The arguments must correspond properly (after type promotion) with the conversion specifier."

You have used "%d" format string, which expects a integral argument appropriate for decimal conversion, yet you haven't provided any arguments, which resulted in an undefined behavior

LihO
  • 41,190
  • 11
  • 99
  • 167