一道有趣的面试题

一道有趣的面试题

填补上空白区域,使函数输出hello world

if(  ?  )
    printf("hello");
else
    printf("world");

解决思路

  • if分支只能执行一条
  • printf函数返回值为输出字符的数目
  • 在if()内部利用printf()输出,条件语句为0(假),执行else语句

具体方法

1、

if(!(printf("Hello"))) 

2、

if(printf("Hello ")!=6)

猜你喜欢

转载自blog.csdn.net/yishengchizha/article/details/79631474