Home > other >  Can we define boolean without a value?
Can we define boolean without a value?

Time:03-13

Can we define boolean without a value?

enter image description here

CodePudding user response:

To use Boolean variables in C you need to #include <stdbool.h> in your headers.

CodePudding user response:

In C, you can declare a boolean variable using the _Bool type. Following as an example. However, it is not a recommended method.

#include <stdio.h>

int main()
{
    printf("Hello, World!\n");
    _Bool k=0, l = 1, m = 324234;
    printf("%d\n", k);
    printf("%d\n", l);
    printf("%d\n", m);
    return 0;
}

You can further use a macro to define _Bool as bool.

#include <stdio.h>
typedef _Bool bool;
int main()
{
    printf("Hello, World!\n");
    bool k=0, l = 1, m = 324234;
    printf("%d\n", k);
    printf("%d\n", l);
    printf("%d\n", m);
    return 0;
}
  • Related