Page 40 - Modular_V2.0_C++_Flikpbook
P. 40
int a = 6;
DOSBox 0.74, Cpu speed: max 100% cycles, Frames 0,
int b = 4; Result of the expression is: 4
Result of the expression is: 8
int c = 2;
Result of the expression is: 5
clrscr();
cout<< "Result of the expression is: " << a - b + c << "\n";
cout<< "Result of the expression is: " << a + b / c << "\n";
cout<< "Result of the expression is: " << (a + b) / c << "\n";
getch();
return 0;
}
TYPE CASTING
Type casting refers to the process of converting a value from one data type to another. For
example, an integer value can be converted into a float type. In C++, there are two types of
type casting:
Implicit Type Casting
Implicit type casting, also known as automatic type conversion, is performed automatically by
the C++ compiler when a smaller data type is converted into a larger one. For example, a char
data type can be automatically converted into an int by the compiler:
char i = 'A';
int num;
num = i;
If you run the above code, the output will be 65, because the American Standard Code for
Information Interchange (ASCII) value of the character 'A' is 65.
Explicit Type Casting
Explicit type casting refers to manually converting one data type into another using a type cast
operator. A type cast operator consists of a data type enclosed in parentheses. For example:
int i = 10;
float f;
f = (float) i;
In the preceding code, the int type value is converted into float type. We use explicit type
casting when C++ does not do a needed conversion automatically.
Recap
An operator is a symbol used to perform mathematical and logical calculations.
Arithmetic operators are general mathematical operators used to perform arithmetic operations.
38
Touchpad MODULAR (Ver. 2.0)

