Friday, February 5, 2010

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.
Eg: 
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.
e.g. 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.
E.g. char c = ‘a’;
Since character types are integral types, arithmetic and logical operations apply on them.

0 Comments: