Learn how to a build a cloud-first strategyRegister Now


Question about boolean expression..

Posted on 2005-04-26
Medium Priority
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...
Question by:Calv1n
  • 2
LVL 30

Accepted Solution

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

David Maisonave :-)
LVL 30

Expert Comment

ID: 13871513
> >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 :-}
LVL 15

Expert Comment

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?
LVL 10

Expert Comment

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


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