Developer community
0 votes
181 views
asked by Expert (13.2k points) 27 43 61 | 181 views

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 by Guru (39.1k points) 10 22 36

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


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

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users