Home  >  Q&A  >  body text

linux - A classic question about printf in C language

The following program, what is the output result?

#include <stdio.h>
int main() {
    int i = 43;
    printf("%d\n",printf("%d",printf("%d",i)));
    return 0;
}

Original series source: Several classic interview questions in C language under Linux

学习ing学习ing2664 days ago1452

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-07-03 11:43:39

    The answer is 43 2 1
    Explanation: printf("%d", i) has a return value and returns the number of outputs
    The above code can be converted to:

    int i = 43;
    a = printf("%d", i) # output: 43
    b = printf("%d", a) # output: 2
    printf("%d", b) # output: 1

    reply
    0
  • Cancelreply