How do I explain the output of this simple C code?

后端 未结 4 2021
青春惊慌失措
青春惊慌失措 2020-12-12 06:11
#include
int main()
{
int i=10;
printf(\"%d\",printf(\"%d\",i));
return(0);
}

Output in Turbo C

102

4条回答
  •  没有蜡笔的小新
    2020-12-12 06:30

    printf() is a C function. It returns an int value equal to the number of bytes it prints.

    In your case, the INNER printf printed "10", so it wrote 2 bytes and will return 2.

    The OUTER printf will therefore print "2".

    Final result: "102" ("10" of the INNER followed by "2" of the OUTER).

提交回复
热议问题