Heim  >  Fragen und Antworten  >  Hauptteil

Linux – Eine klassische Frage zu printf in der C-Sprache

Was ist die Ausgabe des folgenden Programms?

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

Originalserienquelle: Mehrere klassische Interviewfragen in C-Sprache unter Linux

学习ing学习ing2664 Tage vor1450

Antworte allen(1)Ich werde antworten

  • phpcn_u1582

    phpcn_u15822017-07-03 11:43:39

    答案是 43 2 1
    解释:printf("%d", i)有返回值,返回输出的个数
    上面代码可以转换为:

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

    Antwort
    0
  • StornierenAntwort