Bool..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swat
    New Member
    • Nov 2006
    • 7

    Bool..

    Hi this is swat again i want to have a clear concept on bool function why we use it ....how to use it ..and when to use it ....actually what does it mean can anyone explain me about it with some clear examples ..Thanks..
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by swat
    Hi this is swat again i want to have a clear concept on bool function why we use it ....how to use it ..and when to use it ....actually what does it mean can anyone explain me about it with some clear examples ..Thanks..
    Hi swat. Bool is not a function it is a data type which can either be true or false.
    Code:
    bool istrue = false;
    
    if (istrue)
       //this code will not be executed
    
    istrue = true;
    
    if (istrue)
       //this code will be executed

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      Furthermore, a function can return a bool value. This can be helpful in several situations. For example, suppose you have a character, and you want to check if it is a vowel. You can use a function called isVowel to determine if it is a vowel. The function would look like this:

      Code:
      bool isVowel(char ch) {
         // Perform your tests here
         // If ch is a vowel,
         return true;
         // If it's not a vowel,
         return false;
      }
      You would call the function like this:

      Code:
      // code here...
      if (isVowel(myCharVariable)) { // myCharVariable is a vowel
         // Do something here
      } else { // myCharVariable is NOT a vowel
         // Do something else
      }
      bool returning functions can be very useful in simplifying tests that you will repeat throughout your program.

      Comment

      Working...