Member Avatar for Falcon25

Hello guys,

I've recently come across this problem and have spent quite a bit of time trying to comprehend what the question is actually telling me to do :S

.If a, b, c are bool-variables, a is true, but b and c are false, write an expression that computes the logical value of ( a && b ) || c, assign it to a bool d, and
depending on the result print “d is true” or “d is false”. What does “( a && b ) ||
c” mean

If anyone can help me out then it would be much appreciated :). Sorry that I have not put any code examples, I keep deleting them because I'm not sure if I have to assign a variable a value and then create a function to see if can work it out or something completely different... I'm just lost :/

Recommended Answers

All 5 Replies

&& is the and operator; the way it works is the value it returns is true when both sides of it are true, and only when both sides are true, any other time it returns false.

|| is the or operator; I forget how it returns until I'm actually using it for some reason, but it's about like saying if (x is > y or x is > 15) doSomething();.

! is the not operator; this basically returns the opposite of the boolean value you assign it to. When used in conditionals if (x != 10) this basically saying that if x is not equal to 10 (any other value than 10) to execute the code in the if block.

So basically if I remember correctly the or operator returns true only when both sides are false. So when a is true, b is false, and c is false; the statement (a && b) || c should return false.

The if () conditional only checks for boolean values, even when using integers or strings it returns a true or false value to the if. When the value is true (condition met) then it executes the code block below it. If it returns false (condition not met) it skips the following block of code and checks for an else if or else block.

That should sum it up quite decently, if you need anything else just let me know. Please just note, I'm not the best at explaining my knowledge (hence the reason I don't give too many lessons) so it may be off a little.

commented: You told with exaple and it like "thalaiya suthi mooka thodura mari" tamil proverd its waste I told sort and opt answer -1
commented: (the or operator returns true only when both sides are false) wrong :S -1

hey dude

&&-means logical AND operation
||-means logical OR operation

give problem is
a=true;
b=false;
c=false
then
d=( a && b ) || c
//a && b-means (true && false)
//&&-return true when both input are true here one is true (a) another
//one is false(b) this will return false
//in next step it calculate false || C
// ||-return true when any one of the input true here both are false (a&&b)
// and c so result false will assigned to d
hence result d is false

hey dude

&&-means logical AND operation
||-means logical OR operation

give problem is
a=true;
b=false;
c=false
then
d=( a && b ) || c
//a && b-means (true && false)
//&&-return true when both input are true here one is true (a) another
//one is false(b) this will return false
//in next step it calculate false || C
// ||-return true when any one of the input true here both are false (a&&b)
// and c so result false will assigned to d
hence result d is false

I believe that was my response just in shorter and more confusing words? O_o

Member Avatar for Falcon25

Thanks for all your help guys. Going to mark this one as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.