Search code examples
cbooleanstdbool

Writing a function in C that returns a boolean


As C does not have boolean types, how can I write a function like this in C:

bool checkNumber()
{
   return false;
}

Solution

  • The bool type is defined in the <stdbool.h> header, and is available under the name _Bool otherwise (assuming you're using a C99 compiler). If you don't have C99, you can always invent your own bool type like this:

    typedef enum {false, true} bool;