Ternary operator in C++
#include
using namespace std;
int main () {
cout << ( 70 >= 60 ? 40 > 50 ?"Passed" : "Failed":"56");
int x=( 70 >= 60 ? 40 > 50 ?20 : 30:40);
cout<<( 70 >= 60 ? 40 > 50 ?20 : 30:40);
cout << ( 70 >= 60 ? 40 > 50 ?"Passed" : "Failed":56); // Error .. here we cannot use different types in ternary operator output. So 56 will give an error it has to be a char*
return 0;
No other thing is important but just try to understand the structure of this operator
using namespace std;
int main () {
cout << ( 70 >= 60 ? 40 > 50 ?"Passed" : "Failed":"56");
int x=( 70 >= 60 ? 40 > 50 ?20 : 30:40);
cout<<( 70 >= 60 ? 40 > 50 ?20 : 30:40);
cout << ( 70 >= 60 ? 40 > 50 ?"Passed" : "Failed":56); // Error .. here we cannot use different types in ternary operator output. So 56 will give an error it has to be a char*
return 0;
No other thing is important but just try to understand the structure of this operator
Labels: C++, Ternary Operator
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home