Hack Forums
[Help] Boolean operators in C - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: [Help] Boolean operators in C (/showthread.php?tid=6306822)



Boolean operators in C - schassis - Aug 27, 2025

i do not understand them in the slightest

Code
A. !( 1 || 0 )         ANSWER: 0    
B. !( 1 || 1 && 0 )    ANSWER: 0 (AND is evaluated before OR)
C. !( ( 1 || 0 ) && 0 )  ANSWER: 1 (Parenthesis are useful)

ill start with A, i read it as "not or 1 or 0 so it must equal 0" like how in the fuck does that work?!

i dont understand "!" either; if true: false, if false: true. like what the hell??? why???


RE: Boolean operators in C - webdev77 - Aug 27, 2025

It's the order of operations you aren't seeing or apparently following. Just like in normal math, C also has order of operations.
https://en.cppreference.com/w/c/language/operator_precedence.html

1a. 1 or 0 results in 1
1b. Not 1 results in 0

2a. 1 and 0 results in 0.
2b. 1 or 0 results in 1
2c. Not 1 results in 0

3a. 1 or 0 results in 1
3b. 1 and 0 results in 0
3c. Not 0 results in 1


RE: Boolean operators in C - schassis - Aug 27, 2025

(Aug 27, 2025 03:13 PM)webdev77 Wrote:  It's the order of operations you aren't seeing or apparently following. Just like in normal math, C also has order of operations.
https://en.cppreference.com/w/c/language/operator_precedence.html

1a. 1 or 0 results in 1
1b. Not 1 results in 0

2a. 1 and 0 results in 0.
2b. 1 or 0 results in 1
2c. Not 1 results in 0

3a. 1 or 0 results in 1
3b. 1 and 0 results in 0
3c. Not 0 results in 1

oh my god i get it now! haha!

the order of operations is what i didnt know existed, thank you dude

i hate being slow tho, like i can feel my slowness - its aggravating


RE: Boolean operators in C - webdev77 - Aug 27, 2025

(Aug 27, 2025 03:49 PM)schassis Wrote:  oh my god i get it now! haha!

the order of operations is what i didnt know existed, thank you dude

i hate being slow tho, like i can feel my slowness - its aggravating

You're very much welcome. Keep at it and you'll be building fun stuff in no time.

Here's a freely available hex dump function that'll help you when you play around with strings and any buffers containing non-printable characters. I don't know if you have covered strings and buffers in C yet but you likely will soon if you haven't yet.

Function (Click to View)