Explain numeric, character and boolean data types.
Various data types in C++ :Numeric : - This is a fundamental type provided by C++ language. Integers, Floating point types come under this.
Boolean : - Can have one of the two values, true or false. It is used to express the results of a logical operations. They are internally stored as number. A non-zero value is considered true whereas zero is false.
-
Example :Void f(int x, int y)
{
Bool b;
If (x == y)
b = true;
}
- Thus, value of b becomes true if x equals y.
- A common use of bool is as the type of the result of a function that tests some condition.
-
For example :bool isopen(File *fp);
Character :- A variable of type char can hold any character of the implementation’s character set. It takes 1 byte of storage and it can hold 256 different values.
-
For example :char c = ‘a’;
- Since character types are integral types, arithmetic and logical operations apply on them.
When do you use bool data type?
- The bool data type can take only two values true or false.