Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
984 views
in Computer by (71.3k points)

Explain conditional operator with suitable example?

1 Answer

+1 vote
by (76.5k points)
selected by
 
Best answer

Conditional operator is also known as ternary operator because it requires three operands and can be used to replace simple if-else code. It is used to check the condition and execute first expression if condition is true else execute other.

Syntax:

Conditional expression? Expression 1 : Expression 2;

Explanation:

If the conditional expression is true then expression 1 executes otherwise expression 2 executes.

Example:

int y=10,x;

x=y>10?1:0;

cout<<x;

Output: 0

Related questions

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...