+ 6
Please anyone explain the concept of ternary operators?
In C++
17 ответов
+ 11
Parenthesis make it readable and eye-pleasing!
a = 5 > 4 ? ( 3 > 8 ? 40 : 20 ) : 30;
or
if (5 > 4)
if (3 > 8)
40
else
20
else
30
+ 3
Advantage of Ternary Operator -:
Using ?: reduce the number of line codes and improve the performance of application.
Syntax
expression-1 ? expression-2 : expression-3
In the above symbol expression-1 is condition and expression-2 and expression-3 will be either value or variable or statement or any mathematical expression. If condition will be true expression-2 will be execute otherwise expression-3 will be executed.
+ 3
Yes bro i.like the question. Firstly 5>4 condition becomes true it will be 40 and if 3>8 it will be 40 if at all 3<8 ut will be 20 and 4<5 it will be 30
+ 2
But how this work
Int a;
a=5>4?3>8?40:20:30;
What is the output?
+ 2
5 is greater than 4 result is 40.
Next step is execute 3>8 3 is less than 8 and and result is 20.
+ 2
" But what is the input to get 30 as answer in this program? "
An example to make the first condition gets evaluated as false might be
4 > 5 ? (...) : 30
+ 2
it is short hand operator of if else statement used in expression
+ 2
Ternary operator is like a if else
Ex c=X<y?X:y
in the statement if X<y then X is assigned in C otherwise y is assigned in c
+ 1
Okkk bro
+ 1
A ternary operation assign value to variable based on condition . Let me explain by example-
If boolean isValid = x>y? true:false
1. It will check if x is greater than y . Operation 1
2. If operation1 comes to true then true got assigned to isValid variable.
3.if operation comes to false then false value got assigned to isValid variable.
0
But what is the input to get 30 as answer in this program?
0
Oke
0
Thanks i understand it now
0
Yes i know
0
Guys I already understand it check upper comments and thanks
0
In Java
Boolean bool= (10 >2) ? true : false;
If the (10 > 2 ) is true then the bool have true otherwise false