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

前端 未结 3 2006
死守一世寂寞
死守一世寂寞 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:22

    C99 allows //-style comments, C89 does not. So, to translate:

    C99:

     printf("C%d\n",(int)(90-(-4.5     /*Some  comment stuff*/
                             -4.5)));
    // Outputs: 99
    

    C89:

    printf("C%d\n",(int)(90-(-4.5/      
                             -4.5)));
    /* so  we get 90-1 or 89 */
    

提交回复
热议问题