search
Login

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

0 votes
164 views
asked Expert 13.2k points 26 40 57

1 Answer

0 votes
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.

Program: Program to print some thing with out using semicolon(;)

#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:

Hello World

Explanation:

The if statement checks for condition whether the return value of printf("Hello World") is greater than

0. Printf function returns the length of the string printed. Hence the statement if (printf("Hello World"))

prints the string "Hello World".
answered Guru 39.1k points 10 21 32

Related questions

4 votes
2 answers 470 views
470 views
print a semicolon without using a semicolon anywhere in the code.
asked Smita Advisor 7.1k points 10 22 42
0 votes
1 answer 930 views
930 views
Write a program in C to display a message without using semi colon anywhere in program
asked marvel
0 votes
1 answer 48 views
0 votes
2 answers 132 views
0 votes
1 answer 1.6K views
1.6K views
how to Write a C function that reverses the words in a string without using any memory overhead.??
asked anonymous
...