The following is an example of how to define and use a bool datatype in C
typedef enum { false, true } bool;
bool myVar = true;
if (myVar)
{
// do something
}
Or using an int (any integer is considered true, but not 0 ofc);
int notZero=1;
while(notZero)
{
scanf("%d",¬Zero);
}
Finally using stdbool.h (probably preferred);
#include <stdbool.h>
bool condition=true;
while(condition)
{
// do something
}
With regards to C++, I'm not so sure we even need to #include stdbool.h
No comments:
Post a Comment
Note: only a member of this blog may post a comment.