Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Question about boolean expression..

Posted on 2005-04-26
4
Medium Priority
?
228 Views
Last Modified: 2010-04-01
I am studying c++ and I am trying to figure out a question for a practice exam. It goes as follows:

Assume you have three int variables x =2, y=6 and z. Choose the value of z in the following:

z = (y/z>0) ? x : y;

am I correct in stating z=3 because the "?" is basically stating "if the previous expression is true (y/z > 0) then z =x, if it is false then y = z ? I am just making sure I am clear on what this expression is saying...


Thank you for your help...
0
Comment
Question by:Calv1n
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 500 total points
ID: 13871508
Hi Calv1n,
> >m I correct in stating z=3
No.
z would equal 2

David Maisonave :-)
Cheers!
0
 
LVL 30

Expert Comment

by:Axter
ID: 13871513
Calv1n,
> >if the previous expression is true (y/z > 0) then z =x
That's right, but x equals 2, and therefore z will equal 2

David Maisonave :-}
0
 
LVL 15

Expert Comment

by:efn
ID: 13872971
How do you know y/z > 0 when you don't know what the value of z is?  It seems to me that y/z > 0 is true only when z is in the range from 1 to 6.  Am I missing something?
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 13873114
Ok, the expression says as u said above
But the final value of z would depend on the value of z befoe the expr is evaluated
For example,
if initially z = 1 to 6, then y/z >0, thus, z = x, i.e. z = 2 in this case
if initially z > 6 or z < 0, then, then y/z <= 0, thus z = y, i.e. z = 6 in this case

HTH
Amit
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question