How to use boolean function in c? | Sololearn: Learn to code for FREE!


How to use boolean function in c?

4/3/2019 5:22:30 PM


8 Answers

New Answer


NOTE: There is NO Boolean type in C!! Logical operators are usually used with conditional statements. The  two basic logical operators are:   &&  for logical AND,  | |  for logical OR. Beware  &  and  |  have a different  meaning for bitwise AND and OR. Logical operations which exist in C: == ,  != ,  | | ,  &&. [ Edited: ] Aruna, Here is an example of boolean as a subtype of int:


The stdbool.h header file provides support for bool type in C language (which doesn't by default). However, a function returning int type value of either 1 or 0 is commonly used as well; considering C language assumes a zero to be false and anything nonzero to be true. Read the following link for more comprehensive explanation: And here's a little sample using bool type with stdbool.h header, as well a function returning int as boolean: #include <stdio.h> #include <stdbool.h> int is_even(int n) { return n % 2 == 0; } int main() { bool yes = true; bool no = false; if(yes) puts("Yes"); if(!no) puts("No"); if(is_even(2)) printf("2 is even number\n"); if(!is_even(3)) printf("3 is odd number\n"); } Hth, cmiiw




Then what is the use of stdbool. h statement


Thank you


You're welcome, happy coding 👍