using nested printf statements giving strange output

后端 未结 3 1127
长情又很酷
长情又很酷 2021-01-23 17:55

I recently came across this code and I\'m unable to understand how it works

#include
int main(){
    printf(\"Line 1\\n\",
    printf(\"Line 2\\n\         


        
3条回答
  •  执笔经年
    2021-01-23 18:29

    This isn't strange at all. Expressions are evaluated (executed) from within to outside, just like mathematical expressions.

    So put it simple terms: the expression with the most parentheses around it is evaluated / executed first.

    Simplified it is:

    printf("1", printf("2", printf("3", printf("4"))));
    

提交回复
热议问题