Can we write a print statement within if parentheses?

If-Else is a decision-making statement, where the result will be either true or false. If the statement accepts boolean values – if the value is true then it will execute the block of statements below it otherwise not. If no curly braces ‘{‘ and ‘}’ is provides after if(condition) then by default if statement will consider the immediately below statement to be inside its block.

Decision-making statements in programming languages decide the direction of the flow of program execution. If is one of such a decision-making statement.

If any printf() or std::cout statement is written at the place of condition within if block then the Output Window will get the output as whatever written at the place of condition, and this condition will be always evaluated as true. So if statement will be executed as a true condition. Below is the illustration of the same:






// C++ program to print a string
// within conditional statement
#include <iostream>
using namespace std;
// Driver Code
int main()
    // Always evaluated as true
    if (cout << "Welcome to ") {
        cout << "GeeksforGeeks";
        cout << "GFG";
    return 0;



Welcome to GeeksforGeeks

Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.