Explaination of conditional operators

R

richie05 bal

wondering if somebody can explain how this works.

1. bool result = (!a || b <= 0) && (!c || d <=0);

2. int b = (x >0) ;

if somebody could point to some tutorial that would be great too.

Thanks in advance.
 
R

red floyd

wondering if somebody can explain how this works.

1. bool result = (!a || b <= 0) && (!c || d <=0);

2. int b = (x >0) ;

if somebody could point to some tutorial that would be great too.

Thanks in advance.

What does your textbook say about how to evaulate boolean expressions?
 
F

Fred Zwarts

richie05 bal said:
wondering if somebody can explain how this works.

1. bool result = (!a || b <= 0) && (!c || d <=0);

2. int b = (x >0) ;

if somebody could point to some tutorial that would be great too.

Thanks in advance.

The answer depends on the types of a, b, c, d and y.
How it works? The compiler will use the operators that are defined for these types.
These operators return a value which also has a type.
Depending on the resulting type, another operator that is defined for this type is used,
until the whole expression is evaluated.
If an operator is not found for a type, or when it is ambiguous, the compiler will emit a message.
To find the order of the evaluation of the subexpressions,
read your textbook about precedence of operators.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top