Ternary Operator in C++

Structure of the Problem Requirements 

Ternary operator used in C++ programming to write if else statement in program in one line. There is no difference between simple if else condition which is very common in programming and ternary operator (if else condition), compiler treat both code same but programmer used ternary operator to save the keystrokes.

Source Code

#include<iostream>
using namespace std;
int main ()
{
 cout<<"\t \t \t LEP Tutorials \n \n \n ";
 int z,x ,y ;
 cout<<" Enter Your Number :  ";
 cin>>x;
 cout<<endl;
 cout<<"  Enter Your Number :  ";
 cin>>y;
 cout<<endl;
 z = (x > y) ? x : y;
 cout<<" The Greatest Number is : "<<z;
  return 0;
}

Output of the Program

Ternary operator in C++


Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment