技术怪题

时间:2022-04-22
本文章向大家介绍技术怪题,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

有些公司的题真的是会让咱们大跌眼镜。不信,看下面一道题。

int main() { if( )    {  printf("Hello "); } else { printf("World !!!"); } return 0; } 在if里面请写入语句 使得打印出 hello world。

解答:

#include<stdio.h> 
int main()  
{  
 if(!printf("hello "))  // 加入!printf("hello ") 
 {   
  printf("Hello");    
  }  
 else 
   {     
   printf("World");  
  }  
 return 0;  
}  

这样看可能有点迷糊,再举个例子就会真相大白了。

#include<stdio.h> 
int main()  
{  
 if(!printf("hello "))    
 {   
  printf("迷惑你的啦!");    
  }  
 else 
   {     
   printf("World");  
  }  
 return 0;  
}  

运行结果为:

提示:printf("hello "))的返回值是打印输出的字符个数