cs:c_language:boolean_expressions
Return to Home page
If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it
You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/cs/c_language/boolean_expressions?difftype=sidebyside&do=diff&rev2%5B0%5D=1551188114&rev2%5B1%5D=1606429133
Differences
This shows you the differences between two versions of the page.
— | cs:c_language:boolean_expressions [2024/04/08 22:35] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Boolean Expressions ====== | ||
+ | **Concepts: | ||
+ | Boolean expressions (and '' | ||
+ | **Text:**\\ | ||
+ | Some examples regarding boolean expressions, | ||
+ | |||
+ | Examples have been explained with comments in the code. | ||
+ | |||
+ | **Solution: | ||
+ | |||
+ | <file C boolean_expressions.c> | ||
+ | /* Examples regarding boolean expressions */ | ||
+ | |||
+ | #include < | ||
+ | |||
+ | |||
+ | int main() { | ||
+ | | ||
+ | int res; | ||
+ | int x = 2, y = 3; | ||
+ | |||
+ | /* In C, a number different than 0 is a TRUE value */ | ||
+ | if (-10) { | ||
+ | printf(" | ||
+ | } | ||
+ | |||
+ | /* A false condition in C is the number 0 */ | ||
+ | if (0) { | ||
+ | printf(" | ||
+ | }else{ | ||
+ | printf(" | ||
+ | } | ||
+ | |||
+ | | ||
+ | res = 3+2*5; /* res=13 */ | ||
+ | if (res) { /* 13 is a True value */ | ||
+ | printf(" | ||
+ | } | ||
+ | |||
+ | /* res that is equal to 13 is greater than the 7. | ||
+ | The comparison is therefore a TRUE value, but | ||
+ | NOT TRUE = FALSE */ | ||
+ | if ( !(res> | ||
+ | printf(" | ||
+ | }else{ | ||
+ | printf(" | ||
+ | } | ||
+ | | ||
+ | /* 2 > 5 is FALSE and 3 < 4 is TRUE, i.e, | ||
+ | FALSE OR TRUE = TRUE, therefore the | ||
+ | | ||
+ | than 0, in this case it contains the | ||
+ | value 1 */ | ||
+ | res = 2 > 5 || 3 < 4; /* 0 OR 1 */ | ||
+ | printf(" | ||
+ | |||
+ | /* x=2; y=3; | ||
+ | 2 >= 3 is FLASE, 3==3 is TRUE, 2!=3 is FALSE | ||
+ | | ||
+ | | ||
+ | | ||
+ | res = (x >= y && x+1==y) || !(x!=y); | ||
+ | printf(" | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | **Output: | ||
+ | The output of this program is: | ||
+ | <code bash> | ||
+ | A: True | ||
+ | B: False | ||
+ | C: True | ||
+ | D: False | ||
+ | E: 1 | ||
+ | F: 0 | ||
+ | </ |
If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it
You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/cs/c_language/boolean_expressions?difftype=sidebyside&do=diff&rev2%5B0%5D=1551188114&rev2%5B1%5D=1606429133
/web/htdocs/www.skenz.it/home/data/pages/cs/c_language/boolean_expressions.txt · Last modified: 2024/04/08 22:35 by 127.0.0.1