printf() with no arguments in C compiles fine. how?

前端 未结 10 1964
后悔当初
后悔当初 2020-12-02 00:10

I tried the below c program & I expected to get compile time error, but why compiler isn\'t giving any error?

#include 
int main(void)
{
          


        
10条回答
  •  借酒劲吻你
    2020-12-02 01:03

    This compiles well. Because it matches the printf() prototype which is

    printf(const char *,...);
    

    During run-time the call

    printf("%d\n");
    

    Tries to fetch the value from second argument and since you have not passed anything it might get some garbage value and print it out so the behavior is undefined here.

提交回复
热议问题