Scope of #define preprocessor in C

前端 未结 6 1851
孤街浪徒
孤街浪徒 2020-12-09 09:19

The scope of #define is till the end of the file. But where does it start from. Basically I tried the following code.

 #include
          


        
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 09:58

    Here is what roughly looks like after the preprocessor done with your file:

     void fun();
     int main()
     {
        printf("%f \n",3.14);
       
        fun();
        return 0;
     }
     void fun(){
     printf("%f \n",3.141516);}
    

    These are the lines that go to the compiler for compilation(I discarded many of the codes for the sake of clarity, only kept what you coded). As the preprocessor replaces the #define directive with the text/value you provided thus you don't see the #define directives anymore after preprocessing. So it is clear what is going to be printed on the console/terminal.

提交回复
热议问题