Logical Operators, Expressions & Condition Statements (boolean values)Improve INSERT-per-second performance of SQLite?Using boolean values in CPython's equivalent of && (logical-and) in an if-statementWhy does C not have a logical assignment operator?Performance efficiency… conditional statements vs logical expressions in JavascriptRetrieve the result of an OR logic operation in JSLogical Boolean Negation Operator Precedence and AssociationAre || and ! operators sufficient to make every possible logical expression?Compare multiple boolean valuesLogical equality expression in Javascript
Is it possible to create light that imparts a greater proportion of its energy as momentum rather than heat?
Can a rocket refuel on Mars from water?
How can I tell someone that I want to be his or her friend?
What is the intuition behind short exact sequences of groups; in particular, what is the intuition behind group extensions?
Is delete *p an alternative to delete [] p?
A reference to a well-known characterization of scattered compact spaces
What does it mean to describe someone as a butt steak?
What's the point of deactivating Num Lock on login screens?
Can I ask the recruiters in my resume to put the reason why I am rejected?
How to take photos in burst mode, without vibration?
Neighboring nodes in the network
I'm flying to France today and my passport expires in less than 2 months
What killed these X2 caps?
Arrow those variables!
Doing something right before you need it - expression for this?
How can saying a song's name be a copyright violation?
Is there a hemisphere-neutral way of specifying a season?
How do conventional missiles fly?
Etiquette around loan refinance - decision is going to cost first broker a lot of money
Do I have a twin with permutated remainders?
If a Gelatinous Cube takes up the entire space of a Pit Trap, what happens when a creature falls into the trap but succeeds on the saving throw?
What is the word for reserving something for yourself before others do?
What's the difference between 'rename' and 'mv'?
Could gravitational lensing be used to protect a spaceship from a laser?
Logical Operators, Expressions & Condition Statements (boolean values)
Improve INSERT-per-second performance of SQLite?Using boolean values in CPython's equivalent of && (logical-and) in an if-statementWhy does C not have a logical assignment operator?Performance efficiency… conditional statements vs logical expressions in JavascriptRetrieve the result of an OR logic operation in JSLogical Boolean Negation Operator Precedence and AssociationAre || and ! operators sufficient to make every possible logical expression?Compare multiple boolean valuesLogical equality expression in Javascript
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
So I am going over a few things in C programming, which I've gone over before.
However, I'm having a hard time recalling a couple of things that are becoming relevant again. I'm starting to write more complex programs, which are using more and more conditional statements, and I can't quite get them down right.
To recap, I know that in C logical operators determine a value of a condition in one of two ways, true or false. Which really equates to either 1 or 0.
Take the following expression as an example:
(if x
is 4
, y
is 5
, z is 3
)
x > z && y > z
Plug in the values...
4 > 3 && 5 > 3
So in terms of Boolean logic...
I know that the value of this statement is actually:1 && 1
which is 1 (true)
or...
(with same variable values as declared above)
z >= x && x <= y
The value of this statement is actually:0 && 1
which is 0 (false because of the logical &&)
So here's where I need help...
I cant remember how to equate things in a few different forms of expressions like this one:
new values: x = 3
, y = 0
, z = -3
)
x && y || z
what is the Boolean value of something like this? Without any operators like <
, >
, ==
, and !=
?
would it be...
x && y || z
1 0 1
which is 1 for true? because the x && y becomes false (because any false with && is a false) but then its followed with the ||
(OR) which if there is true it is true?
Is my question making sense?
or what about an expression that looks like this...
(if x = 5
, y = 1
)
!x + !!y
what would be the Boolean value here? Is it
!(5) + !(!)(1)
0 1 which would be 1 true?
Do I add the zero and one? Probably not.
I'm probably overthinking this.
c conditional logical-operators boolean-logic
add a comment |
So I am going over a few things in C programming, which I've gone over before.
However, I'm having a hard time recalling a couple of things that are becoming relevant again. I'm starting to write more complex programs, which are using more and more conditional statements, and I can't quite get them down right.
To recap, I know that in C logical operators determine a value of a condition in one of two ways, true or false. Which really equates to either 1 or 0.
Take the following expression as an example:
(if x
is 4
, y
is 5
, z is 3
)
x > z && y > z
Plug in the values...
4 > 3 && 5 > 3
So in terms of Boolean logic...
I know that the value of this statement is actually:1 && 1
which is 1 (true)
or...
(with same variable values as declared above)
z >= x && x <= y
The value of this statement is actually:0 && 1
which is 0 (false because of the logical &&)
So here's where I need help...
I cant remember how to equate things in a few different forms of expressions like this one:
new values: x = 3
, y = 0
, z = -3
)
x && y || z
what is the Boolean value of something like this? Without any operators like <
, >
, ==
, and !=
?
would it be...
x && y || z
1 0 1
which is 1 for true? because the x && y becomes false (because any false with && is a false) but then its followed with the ||
(OR) which if there is true it is true?
Is my question making sense?
or what about an expression that looks like this...
(if x = 5
, y = 1
)
!x + !!y
what would be the Boolean value here? Is it
!(5) + !(!)(1)
0 1 which would be 1 true?
Do I add the zero and one? Probably not.
I'm probably overthinking this.
c conditional logical-operators boolean-logic
1
What is the value ofx && y || z
? I've been programming professionally in C for over thirty years, and I haven't a clue. Sure, I could go to the standard docs and look up operator precedence and find out, or I could just not write such monstrosities in the first place--put in parentheses to make it obvious and get on with my work.
– Lee Daniel Crocker
Mar 8 at 0:37
add a comment |
So I am going over a few things in C programming, which I've gone over before.
However, I'm having a hard time recalling a couple of things that are becoming relevant again. I'm starting to write more complex programs, which are using more and more conditional statements, and I can't quite get them down right.
To recap, I know that in C logical operators determine a value of a condition in one of two ways, true or false. Which really equates to either 1 or 0.
Take the following expression as an example:
(if x
is 4
, y
is 5
, z is 3
)
x > z && y > z
Plug in the values...
4 > 3 && 5 > 3
So in terms of Boolean logic...
I know that the value of this statement is actually:1 && 1
which is 1 (true)
or...
(with same variable values as declared above)
z >= x && x <= y
The value of this statement is actually:0 && 1
which is 0 (false because of the logical &&)
So here's where I need help...
I cant remember how to equate things in a few different forms of expressions like this one:
new values: x = 3
, y = 0
, z = -3
)
x && y || z
what is the Boolean value of something like this? Without any operators like <
, >
, ==
, and !=
?
would it be...
x && y || z
1 0 1
which is 1 for true? because the x && y becomes false (because any false with && is a false) but then its followed with the ||
(OR) which if there is true it is true?
Is my question making sense?
or what about an expression that looks like this...
(if x = 5
, y = 1
)
!x + !!y
what would be the Boolean value here? Is it
!(5) + !(!)(1)
0 1 which would be 1 true?
Do I add the zero and one? Probably not.
I'm probably overthinking this.
c conditional logical-operators boolean-logic
So I am going over a few things in C programming, which I've gone over before.
However, I'm having a hard time recalling a couple of things that are becoming relevant again. I'm starting to write more complex programs, which are using more and more conditional statements, and I can't quite get them down right.
To recap, I know that in C logical operators determine a value of a condition in one of two ways, true or false. Which really equates to either 1 or 0.
Take the following expression as an example:
(if x
is 4
, y
is 5
, z is 3
)
x > z && y > z
Plug in the values...
4 > 3 && 5 > 3
So in terms of Boolean logic...
I know that the value of this statement is actually:1 && 1
which is 1 (true)
or...
(with same variable values as declared above)
z >= x && x <= y
The value of this statement is actually:0 && 1
which is 0 (false because of the logical &&)
So here's where I need help...
I cant remember how to equate things in a few different forms of expressions like this one:
new values: x = 3
, y = 0
, z = -3
)
x && y || z
what is the Boolean value of something like this? Without any operators like <
, >
, ==
, and !=
?
would it be...
x && y || z
1 0 1
which is 1 for true? because the x && y becomes false (because any false with && is a false) but then its followed with the ||
(OR) which if there is true it is true?
Is my question making sense?
or what about an expression that looks like this...
(if x = 5
, y = 1
)
!x + !!y
what would be the Boolean value here? Is it
!(5) + !(!)(1)
0 1 which would be 1 true?
Do I add the zero and one? Probably not.
I'm probably overthinking this.
c conditional logical-operators boolean-logic
c conditional logical-operators boolean-logic
edited Mar 8 at 0:41
Jonathan Leffler
574k956881041
574k956881041
asked Mar 8 at 0:09
Jedi_Sk8TricksJedi_Sk8Tricks
215
215
1
What is the value ofx && y || z
? I've been programming professionally in C for over thirty years, and I haven't a clue. Sure, I could go to the standard docs and look up operator precedence and find out, or I could just not write such monstrosities in the first place--put in parentheses to make it obvious and get on with my work.
– Lee Daniel Crocker
Mar 8 at 0:37
add a comment |
1
What is the value ofx && y || z
? I've been programming professionally in C for over thirty years, and I haven't a clue. Sure, I could go to the standard docs and look up operator precedence and find out, or I could just not write such monstrosities in the first place--put in parentheses to make it obvious and get on with my work.
– Lee Daniel Crocker
Mar 8 at 0:37
1
1
What is the value of
x && y || z
? I've been programming professionally in C for over thirty years, and I haven't a clue. Sure, I could go to the standard docs and look up operator precedence and find out, or I could just not write such monstrosities in the first place--put in parentheses to make it obvious and get on with my work.– Lee Daniel Crocker
Mar 8 at 0:37
What is the value of
x && y || z
? I've been programming professionally in C for over thirty years, and I haven't a clue. Sure, I could go to the standard docs and look up operator precedence and find out, or I could just not write such monstrosities in the first place--put in parentheses to make it obvious and get on with my work.– Lee Daniel Crocker
Mar 8 at 0:37
add a comment |
1 Answer
1
active
oldest
votes
We know that (cppreference conversion):
- zero value evaluates to false.
- nonzero value evaluates to true. Any nonzero value.
-3
is true.1
is true.INT_MAX
is true.
We also know about operator precedence:
- && has higher precedence than ||
- which means, first && is evaluated, then ||
We also know that true
and false
in C are just macros for 1
and 0
defined in stdbool.h
, so they have the int
type. C does not has "real" boolean values, only boolean _Bool
type. The logical operators &&
||
and !
evaluate to int
(!) type values 1
or 0
only, see cppreference.
So:
3 && 0 || -3
is equal to:
(true && false) || true
which evaluates to 1
.
!5 + !!1
The !
has higher precedence.
The value of !
operator is 1
(true) in case of zero. The value of !
operator is 0
(false) in case of nonzero expression.
So it's:
(! true) + (! (! true) )
false + true
0 + 1
1
Thank you @KamilCuk . This makes sense. So to be sure I'm understanding you correctly, here's another example: (c = 2, d = -3, a = 0) with the expression: 2 < !d + d Which would be: 1 < 0 + 1 and ultimately be false: 1 < 1 (false) am I on the right track here? Thanks so much!
– Jedi_Sk8Tricks
Mar 8 at 19:04
I think yes, you are correct.
– Kamil Cuk
Mar 9 at 6:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054831%2flogical-operators-expressions-condition-statements-boolean-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
We know that (cppreference conversion):
- zero value evaluates to false.
- nonzero value evaluates to true. Any nonzero value.
-3
is true.1
is true.INT_MAX
is true.
We also know about operator precedence:
- && has higher precedence than ||
- which means, first && is evaluated, then ||
We also know that true
and false
in C are just macros for 1
and 0
defined in stdbool.h
, so they have the int
type. C does not has "real" boolean values, only boolean _Bool
type. The logical operators &&
||
and !
evaluate to int
(!) type values 1
or 0
only, see cppreference.
So:
3 && 0 || -3
is equal to:
(true && false) || true
which evaluates to 1
.
!5 + !!1
The !
has higher precedence.
The value of !
operator is 1
(true) in case of zero. The value of !
operator is 0
(false) in case of nonzero expression.
So it's:
(! true) + (! (! true) )
false + true
0 + 1
1
Thank you @KamilCuk . This makes sense. So to be sure I'm understanding you correctly, here's another example: (c = 2, d = -3, a = 0) with the expression: 2 < !d + d Which would be: 1 < 0 + 1 and ultimately be false: 1 < 1 (false) am I on the right track here? Thanks so much!
– Jedi_Sk8Tricks
Mar 8 at 19:04
I think yes, you are correct.
– Kamil Cuk
Mar 9 at 6:34
add a comment |
We know that (cppreference conversion):
- zero value evaluates to false.
- nonzero value evaluates to true. Any nonzero value.
-3
is true.1
is true.INT_MAX
is true.
We also know about operator precedence:
- && has higher precedence than ||
- which means, first && is evaluated, then ||
We also know that true
and false
in C are just macros for 1
and 0
defined in stdbool.h
, so they have the int
type. C does not has "real" boolean values, only boolean _Bool
type. The logical operators &&
||
and !
evaluate to int
(!) type values 1
or 0
only, see cppreference.
So:
3 && 0 || -3
is equal to:
(true && false) || true
which evaluates to 1
.
!5 + !!1
The !
has higher precedence.
The value of !
operator is 1
(true) in case of zero. The value of !
operator is 0
(false) in case of nonzero expression.
So it's:
(! true) + (! (! true) )
false + true
0 + 1
1
Thank you @KamilCuk . This makes sense. So to be sure I'm understanding you correctly, here's another example: (c = 2, d = -3, a = 0) with the expression: 2 < !d + d Which would be: 1 < 0 + 1 and ultimately be false: 1 < 1 (false) am I on the right track here? Thanks so much!
– Jedi_Sk8Tricks
Mar 8 at 19:04
I think yes, you are correct.
– Kamil Cuk
Mar 9 at 6:34
add a comment |
We know that (cppreference conversion):
- zero value evaluates to false.
- nonzero value evaluates to true. Any nonzero value.
-3
is true.1
is true.INT_MAX
is true.
We also know about operator precedence:
- && has higher precedence than ||
- which means, first && is evaluated, then ||
We also know that true
and false
in C are just macros for 1
and 0
defined in stdbool.h
, so they have the int
type. C does not has "real" boolean values, only boolean _Bool
type. The logical operators &&
||
and !
evaluate to int
(!) type values 1
or 0
only, see cppreference.
So:
3 && 0 || -3
is equal to:
(true && false) || true
which evaluates to 1
.
!5 + !!1
The !
has higher precedence.
The value of !
operator is 1
(true) in case of zero. The value of !
operator is 0
(false) in case of nonzero expression.
So it's:
(! true) + (! (! true) )
false + true
0 + 1
1
We know that (cppreference conversion):
- zero value evaluates to false.
- nonzero value evaluates to true. Any nonzero value.
-3
is true.1
is true.INT_MAX
is true.
We also know about operator precedence:
- && has higher precedence than ||
- which means, first && is evaluated, then ||
We also know that true
and false
in C are just macros for 1
and 0
defined in stdbool.h
, so they have the int
type. C does not has "real" boolean values, only boolean _Bool
type. The logical operators &&
||
and !
evaluate to int
(!) type values 1
or 0
only, see cppreference.
So:
3 && 0 || -3
is equal to:
(true && false) || true
which evaluates to 1
.
!5 + !!1
The !
has higher precedence.
The value of !
operator is 1
(true) in case of zero. The value of !
operator is 0
(false) in case of nonzero expression.
So it's:
(! true) + (! (! true) )
false + true
0 + 1
1
edited Mar 8 at 0:29
answered Mar 8 at 0:22
Kamil CukKamil Cuk
13.4k1529
13.4k1529
Thank you @KamilCuk . This makes sense. So to be sure I'm understanding you correctly, here's another example: (c = 2, d = -3, a = 0) with the expression: 2 < !d + d Which would be: 1 < 0 + 1 and ultimately be false: 1 < 1 (false) am I on the right track here? Thanks so much!
– Jedi_Sk8Tricks
Mar 8 at 19:04
I think yes, you are correct.
– Kamil Cuk
Mar 9 at 6:34
add a comment |
Thank you @KamilCuk . This makes sense. So to be sure I'm understanding you correctly, here's another example: (c = 2, d = -3, a = 0) with the expression: 2 < !d + d Which would be: 1 < 0 + 1 and ultimately be false: 1 < 1 (false) am I on the right track here? Thanks so much!
– Jedi_Sk8Tricks
Mar 8 at 19:04
I think yes, you are correct.
– Kamil Cuk
Mar 9 at 6:34
Thank you @KamilCuk . This makes sense. So to be sure I'm understanding you correctly, here's another example: (c = 2, d = -3, a = 0) with the expression: 2 < !d + d Which would be: 1 < 0 + 1 and ultimately be false: 1 < 1 (false) am I on the right track here? Thanks so much!
– Jedi_Sk8Tricks
Mar 8 at 19:04
Thank you @KamilCuk . This makes sense. So to be sure I'm understanding you correctly, here's another example: (c = 2, d = -3, a = 0) with the expression: 2 < !d + d Which would be: 1 < 0 + 1 and ultimately be false: 1 < 1 (false) am I on the right track here? Thanks so much!
– Jedi_Sk8Tricks
Mar 8 at 19:04
I think yes, you are correct.
– Kamil Cuk
Mar 9 at 6:34
I think yes, you are correct.
– Kamil Cuk
Mar 9 at 6:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054831%2flogical-operators-expressions-condition-statements-boolean-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What is the value of
x && y || z
? I've been programming professionally in C for over thirty years, and I haven't a clue. Sure, I could go to the standard docs and look up operator precedence and find out, or I could just not write such monstrosities in the first place--put in parentheses to make it obvious and get on with my work.– Lee Daniel Crocker
Mar 8 at 0:37