473,508 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bool..

7 New Member
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..
Jan 30 '07 #1
2 1852
willakawill
1,646 Top Contributor
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.
Expand|Select|Wrap|Line Numbers
  1. bool istrue = false;
  2.  
  3. if (istrue)
  4.    //this code will not be executed
  5.  
  6. istrue = true;
  7.  
  8. if (istrue)
  9.    //this code will be executed
Jan 30 '07 #2
Ganon11
3,652 Recognized Expert Specialist
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:

Expand|Select|Wrap|Line Numbers
  1. bool isVowel(char ch) {
  2.    // Perform your tests here
  3.    // If ch is a vowel,
  4.    return true;
  5.    // If it's not a vowel,
  6.    return false;
  7. }
You would call the function like this:

Expand|Select|Wrap|Line Numbers
  1. // code here...
  2. if (isVowel(myCharVariable)) { // myCharVariable is a vowel
  3.    // Do something here
  4. } else { // myCharVariable is NOT a vowel
  5.    // Do something else
  6. }
bool returning functions can be very useful in simplifying tests that you will repeat throughout your program.
Jan 30 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2598
by: Pierre Espenan | last post by:
A have a long integer class. The built integer type within a conditional statement returns bool false for int i=0 and bool true for any other non zero value. I want my long integer class to have...
4
2929
by: Nomak | last post by:
Hello, With this code: $ cat -n ifs.cc 1 #include <vector> 2 #include <iostream> 3 4 using std::vector; 5 using std::cin;
19
3333
by: daniel | last post by:
1) is C++ smart enough to automatically use "bits" for bool or will a bool have the size of a charcter (byte). 2) The index of a vector is it an integer (4 byte) or a "long long" with 8 bytes or...
4
10729
by: ORC | last post by:
Is the bool type actually an Int32 with 0 as false and non zero as true? The reason for my question is that I've seen a lot of API calls that return a Int32 implemented in C# as an bool like: ...
10
19105
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
1
1585
by: Bern McCarty | last post by:
What do you make of this? I cannot tell for sure but it almost seems as the the transition thunk to get back from the native bool method to the managed caller is looking at eax and, if any bit is...
4
6461
by: gpg | last post by:
I am using a legacy DLL and need to marshal some structures for use in the DLL. For the most part, I have figured out my needs except for one small item. I have a structure that contain, among...
6
6783
by: zl2k | last post by:
hi, there I am using a big, sparse binary array (size of 256^3). The size may be changed in run time. I first thought about using the bitset but found its size is unchangeable. If I use the...
64
3817
by: shaanxxx | last post by:
I have code which says #define MYBOOL int This code is very old. people who have written is not avaible. I was thinking what could be reason. 1) bool datatype was not available that time (10...
3
6302
by: markb | last post by:
Hi My C# app is being called from a callback from an unmanaged DLL. One of the parameters of the callback is of type BOOL. I am using PInvoke to marshal this to a (managed) bool. The problem is...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.