How does this “hello world!” program work?

后端 未结 2 912
滥情空心
滥情空心 2021-02-01 18:36
int main(void)
{ 
    return(\'yes\', *\"no\", **main, *********printf) (\"hello world!\\n\") *0; 
}

outputs hello world!, but how does it

2条回答
  •  广开言路
    2021-02-01 19:04

    ('yes', *"no", **main, *********printf) 
    

    will evaluate to *********printf, because comma operator evaluates its operands and returns value of last expression. *********printf is equal to printf, as dereferencing function pointer results in the same function pointer; it does nothing.

    Next, result of first parenthesis, printf, is applied to ("hello world!\n") which results in text printed to screen. printf function returns number of characters written. That number is then multiplied with 0 and product is returned by main function.

提交回复
热议问题