Unit C, Chapter-08 Data Types
Unit C, Chapter-08 Data Types
CHAPTER-08
DATA TYPES
Datatype: Data type specifies the type of the value that a variable can store.
b) Float data type: Numeric value with fractional part belongs to float data type. The keyword float is
used to declare it. The size of the variable of float data type requires 4 bytes of memory ranging
from 3.4e-38 to 3.4e38.
Ex: float a;
Modifier of float data type
i. Double data type: The size of the variable of double data type requires 8 bytes of
memory space ranging from 1.7e-308 to 1.7e308.
c) Character (char) data type: All single characters which are used in program belong to character
data type. The keyword char is used to declare the variable of character type. The size of character
variables requires 1 byte of memory space ranging from -128 to 127 (ie the ASCII value of
different characters).
Ex: char ch;
d) Void data type: Is a special data type available in C++. It has no values and doesn’t perform any
operation. It specifies the function does not return any value.
Ex: void main()
e) Boolean (bool): We can use this data type to manipulate logical (boolean) expressions.
Ex: bool legalage;
int age;
The statement:
legalage=true;
2) Relational expression
The expression that uses a relational operator is called relational expression. The resulting value
of this expression is always true(1) or false (0).
Ex: int a=20, b=10;
if(a>b) result is true (1)
3) Logical expression
The expressi on that uses a logical operator is called logical expression. The resulting value of this
expression is always true(1) or false(0). It is used to combine two or more relational expressions.
Ex:
int a=20, b=20, c=5;
if((a>b) && (a>c))
if((F) && (T)) result is false
Evaluation of expression
Expression in a C++ program are evaluated based on priority (precedence) of operator and Associative of an
operator
Associative of an operator
An expression that contains two or more operators of same priority value, then the compiler evaluates the
expression based on associative i.e from left to right associative and right to left associative.
Left to right associative: Evaluating a expression from L to R
Right to left associative: Evaluating a expression from R to L
Ex:
Evaluate 6 * (3+3) / 6 – 3
Method 1:
=6 * (3+3) / 6 - 3
=6 * (3+3) /3
=6 * 6 / 3
=6 * 2
=12
Method 2
=6 * (3+3) / 6 - 3
=6 * 6 / 6 – 3
=36 / 6 – 3
=6 – 3
=3
In the above two methods two possible outputs 12 and 3, but the correct output is 3, because it follows the
rules of priority and associative of arithmetic operators (ie BODMAS rule)
NOTE:
BODMAS Brackets of Division Multiplication Addition Subtraction.
--*********--