Monday, 2 February 2015

Ternary operator in C++

Structure of the Problem Requirements 

Ternary operator used in C++ programming to write if else statement a 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 it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment