C Code: How does these even work?

后端 未结 4 1919
既然无缘
既然无缘 2021-02-04 01:02

I just saw this here

#include 

int main(int argc, char *argv[printf(\"Hello, world!\\n\")]) {}

What this does is print \"Hello

4条回答
  •  死守一世寂寞
    2021-02-04 01:39

    char *argv[printf("Hello, world!\n")])

    printf() returns the number of characters printed.

    So

    int main(int argc, char *argv[printf("Hello, world!\n")]) {}

    is equivalent to

    int main(int argc, char *argv[14]) {}

    plus a call to printf() which prints "Hello World"

提交回复
热议问题