c++ if example

In C++, the "if" statement is used to make decisions based on a condition. Here's an example of how it works:

#include <iostream>
using namespace std;

int main() {
  int num = 10;

  if (num > 5) {
    cout << "The number is greater than 5";
  } else {
    cout << "The number is less than or equal to 5";
  }

  return 0;
}

Explanation: 1. We include the iostream library to use the input/output functions and the "using namespace std" statement to streamline the code. 2. In the main function, we declare an integer variable "num" and initialize it to 10. 3. The "if" statement checks if the value of "num" is greater than 5. 4. If the condition is true, it executes the statement inside the curly braces, which prints "The number is greater than 5". 5. If the condition is false, it executes the statement inside the "else" block, which prints "The number is less than or equal to 5". 6. Finally, the program returns 0 to indicate successful execution.