C++ Data Type

Datatype

It is the type of data, that is going to be processed within the program. A variable can be declared anywhere in the program before its first use.





Type Conversion:

(i) Implicit type conversion

(ii) Explicit type conversion

Implicit type conversion

It will be done by the compiler, by following the rule of lower type converted to higher type.

Eg:  int y = 10;

float z = 10.5,x;

x = y+z; (y is converted to float type by compiler)
x = 10.0 + 10.5

x= 20.5 (result var. x is must be float)

Explicit type conversion

It will be performed by the programmer. According to the need of this in the program.

Syntax: datatype (var) Eg: int y = 10;

float z = 2.5;(resultant type of y+z is float, that is converted explicitly to int type) x = int (y + z);

Now the result is of int type.

Constants

A quantity that does not change is known as constants.

Types of constants:



Integer constants-
-
Eg: 123, 25

Character constants
-   Eg: ‘A’, ‘B’, ‘*’, ‘1’
Real constants
-
Eg: 12.3, 2.5
-  with decimal point
Strings




A sequence of characters is called string. String constants are enclosed in double quotes as follows

“Hello”

Operators

An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations.