I'm trying to make a function with return type as boolean...the syntax of the program seems to be correct but the compiler is giving errors....
The header files I've included are:
#include<stdio.h>
#include<stdlib.h>
the function I've created is:
34.bool checknull(struct node* node){
35. if ( node != NULL )
36. return TRUE;
37.
38. return false;
39.}
and what I'm getting at compile time is
bininsertion.c:34:1: error: unknown type name ‘bool’
bininsertion.c: In function ‘checknull’:
bininsertion.c:36:10: error: ‘TRUE’ undeclared (first use in this function)
bininsertion.c:36:10: note: each undeclared identifier is reported only once for each function it appears in
bininsertion.c:38:9: error: ‘false’ undeclared (first use in this function)
I've tried "TRUE,false" both in small and capital letters but doesn't seem to work...
C does not have boolean data types, and normally uses integers for boolean testing. Zero is used to represent false, and One is used to represent true. For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true.
Though C doesn't support Boolean value. But we can use Logical Operators like '&&', '||' or '!
An introduction to how to use booleans in C C99, the version of C released in 1999/2000, introduced a boolean type. To use it, however, you need to import a header file, so I'm not sure we can technically call it “native”.
an appropriate answer to this is, yes a C standard such as C90, specifically the C99 standard, does implement a bool type.
You should include <stdbool.h>
if you want bool
, true
and false
. Also it's true
, not TRUE
.
If you don't want to include stdbool.h
you can just use the slightly ugly _Bool
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With