Can someone please explain bool and bool functions.
I can only use if/else/switch statements but i'm seeing bool this/that in my tutorial and i don't get it.
Thanks.
Anywhere you need a true or false in your program...your question is not very specific which leads me to believe that you haven't asked the question you came here to ask.
bool is a variable type just like int, long, char,... so you use it just as you would any of those other variable types.
Most likely, you would have a check somewhere in your program to see if something has failed, or a condition is fulfilled. For example, you might have a function to check to see if a string is null-terminated, so you could do it like this:
1 2 3 4 5 6 7 8 9 10 11
// returns true/false
bool isNullTerminated(constchar* str, int len) {
// repeat for every character in the string
for (int i = 0; i < len; ++i) {
// if the string has a NULL character somewhere
if (str[i] == '\0')
returntrue; // say, 'yes it does'
}
// we have run out of characters, therefore it isn't NULL terminated
returnfalse;
}