Saturday, 29 March 2014

Tagged Under:

Did You Know You Can Also Print "Hello World" Without Using Semicolon

Share
Generally when we use printf("") statement, we have to use a semicolon at the end. If printf is used inside an if Condition, semicolon can be avoided.

Yes, You can see the example.

Source Code
 #include<stdio.h> 
 int main(){ 
 //printf returns the length of string being printed 
 if (printf("Hello World\n")) //prints Hello World and returns 11 
 { 
 //do nothing 
 } 
 return 0; 
 } 
   

Output

Explanation:

The if statement checks for condition whether the return value of printf("He llo World") is greater than 0. printf function returns the length of the string printed. Hence the statement if (printf("H ello World")) prints the string "Hello World".


You may also like:

* Draw a Bouncing Ball on Surface using C++ Graphics 

* C++ Program To Implements Snake and Ladder Game ( Graphics )

0 comments:

Post a Comment

Contact Us

Want to ask anything? Be our guest, give us a message.

Name Email * Message *