Conditional operators for comparisons – C++ Program

What it does:

If the first and second number are equal to each other it will print out equal and if they are not equal it will print out as so.

Code:


#include <iostream>
using namespace std;
int main()
{
  int first = 10;
  int second = 20;
  string result;
  result = first == second ? “equal” : “not equal”;
  cout << result << endl;
  return 0;
}//main

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s