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++
#include <iostream>
using namespace std;
int main()
{
if (cout << "Welcome to " ) {
cout << "GeeksforGeeks" ;
}
else
cout << "GFG" ;
return 0;
}
|
Output:
Welcome to GeeksforGeeks
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
25 Oct, 2020
Like Article
Save Article