What is the conditional expression operator, C/C++ Programming

Assignment Help:

The Conditional Expression Operator

An alternate method to using a simple if-else construct is the conditional expressions operator, ?:

 

A conditional expression operator is a ternary operator, it has three operand, whose general format is:

 

expression1 ? expression2 : expression3

 

Here the expression1 is evaluated first, if it is true then the expression 2 is the value of the conditional operator, otherwise the expression 3 is the value.

 

e.g.

                The if else construct

 

if(a>b)

 {

z = a;

 }

else

 {

                z = b;

                       }

 

                This can be written as

 

                                z = (a>b) ? a: b;

 


Related Discussions:- What is the conditional expression operator

Programming and solving problems with a computer, One person who is special...

One person who is specialist at programming and solving problems with a computer Project Description: Potential computer, hardware, programming and software genius, I look

Program to calculate students marks, #include using namespace std; void...

#include using namespace std; void print(int marks_arr[],int cnt) { int ind[cnt]; int i=0; int j=0; int k=0; int s=0; for(k=0;k { ind[k]=0; } int cnt1=0; for(i=0;i

Plugging the memory leak, Problem #1: plugging the memory leak. When you em...

Problem #1: plugging the memory leak. When you employ the "normal" new operator, for example Foo* p = new Foo(), the compiler generates some special code to manage the case while t

Multiple constructor, Constructor public class ListNode {    //...

Constructor public class ListNode {    // package access members; List can access these directly private E data; // data for this node privateListNode nextNode; /

Explain the parts of operators, Explain the parts of operators Assignm...

Explain the parts of operators Assignment Operators The equal (=) sign is used for assigning a value to another. The left hand side has to be a variable (lvalue, which exc

Explain friend for overloading operators, Friend for Overloading Operators ...

Friend for Overloading Operators Sometimes friend functions cannot be avoided. For example with the operator overloading. Consider the following class that have data members to

#program, Ask question #Minimum 100 words accepted program for polishin...

Ask question #Minimum 100 words accepted program for polishing jewels#

Explain about the character constants in c language, Explain about the Char...

Explain about the Character Constants in c language? The character constant is a single alphabet and a single digit or a single special symbol enclosed within a pair of single

What is memory allocation, What is memory allocation? Memory Allocation...

What is memory allocation? Memory Allocation : It is the method of allocating memory storage to program in such that the program can be run.

Stack, write c language program that shows stack overflow..

write c language program that shows stack overflow..

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd