How to use if else statement in c++?

How to use if else statement in c++?, someone asked me to explain?
#include <iostream>
using namespace std;

int main()
  int a,b;
  cout<<"enter the a and b values:";
      cout<<"a is biggest";
      cout<<"a is smallest";
return 0;

c++ program result

Steps to create a simple c++ program:

(1) Creating Source code

Creating includes typing and editing the valid C++ code as per the rules followed by the C++ Compiler.

(2) Saving process:

After typing, the source code should be saved with the extension .cpp

(3) Compilation

This is an important step in constructing a program. In compilation, compiler links the library files with the source code and verifies each and every line of code. If any mistake or error is found, it will throw error message. If there are no errors then it translates the source code into machine readable object file with an extension .obj

(4) Execution

In this stage, the object file becomes an executable file with extension .exe.

Steps to create a source code:

*need for #include <iostream>

using namespace std;

int main()

Usually all C++ programs begin with include statements starting with a #. The symbol # is a directive for the pre-processor. That means, these statements #include <iostream> statement tells the compiler’s pre-processor to include the header file “iostream” in the program. The header file iostream should included in every C++ program to implement input/output functionalities.

 If you fail to include iostream in your program, an error message will occur on cin and cout.

The line using namespace std; tells the compiler to use standard namespace. Namespace collects identifiers used for class, object and variables.

Every C++ program must have a main function. 

The main( ) function is the starting point where all C++ programs begin their execution.

Therefore, the executable statements should be inside the main( ) function.

syntax of if else statement:


 //body of the statement;

Explanation of if else statement:

The if else statement evaluates a condition; if the condition is true then the statement inside the if part will be executed; that is the statement inside the else part will be skipped while, if the condition evaluates to false then the statement inside else part will be executed that is the statement inside if part will be skipped.

Related Article

Post your comments / questions