How does the below program output `C89` when compiled in C89 mode and `C99` when compiled in C99 mode?

前端 未结 3 2004
死守一世寂寞
死守一世寂寞 2021-01-30 04:48

I\'ve found this C program from the web:

#include 

int main(){

    printf(\"C%d\\n\",(int)(90-(-4.5//**/
    -4.5)));

    return 0;
}
         


        
3条回答
  •  迷失自我
    2021-01-30 05:15

    the line comment // is introduced since C99. Therefore your code is equal to this in C89

    #include 
    
    int main(){
    
        printf("C%d\n",(int)(90-(-4.5/
    -4.5)));
    
        return 0;
    }
    /* 90 - (-4.5 / -4.5) = 89 */
    

    and equal to this in C99

    #include 
    
    int main(){
    
        printf("C%d\n",(int)(90-(-4.5
    -4.5)));
    
        return 0;
    }
    /* 90 - (-4.5 - 4.5) = 99*/
    

提交回复
热议问题