Data Types of C++: Data Types: To Solve The Problems of Real Word The Programmer Should Deal With
Data Types of C++: Data Types: To Solve The Problems of Real Word The Programmer Should Deal With
DATA TYPES
Data Types: To solve the problems of real word the programmer should deal with
different types of data. The data should be stored in the computer memory and it
should be processed. To represent the different types of data and to store in
computer memory, C++ has different data types.
Data Type: It is a type of the data using which different types of data can be
represented.
The data type gives the information about the type of data stored in the variable
and a set of operations can be performed with the data.
1. Fundamental (Built- In) Data type: In C++ there are 5 basic data types.
1) Integer: The keyword int is used to declare integers. The whole numbers
can be declared and stored using integers.
The general form of integer declaration is
int variable list;
Ex: int a, b;
Here a and b are variables of type integers in which a whole number can
be stored. The C++ allocates 4 bytes (32 bits) of memory for integer
data.
There are different types of integers
Short int: to store small integers, allocates 2 bytes of memory.
Long int: to store large numbers, allocates 8 bytes of memory
Unsigned int: to store positive numbers, stores the sign of the number
also.
2) Character: The keyword char is used to declare characters. The single
characters can be declared and stored using char data type.
2. Derived Data type: The data types created using fundamental types are
called as derived data types. Derived data types of C++ are
1) Arrays
2) Functions
3) Pointers
4) References
3. User Defined Data type: The data type created using fundamental types
according to the requirements of the user is called as user defined data
types. They are
1) Classes
2) Structures
3) Unions
4) Enumerations
1. Variables: A meaningful name given to a data storage location in computer
memory.
Syntax: data type variable name list;
That is
Data type v1, v2,…..vn;
Depending on the type of the variable declared, the computer will assign
the number of bytes to that variable.
Ex: int num; Here num is a variable of type integer. The computer will
assign 4 bytes of memory for int variable.
The memory address of num variable can be accessed using &num, &
operator gives the address of the variable.
To assign the value to the variable, the syntax is
Variable name=value;
Ex: int a;
a=10;
char ch;
ch=’y’;
Expressions: An expression in C++ is a valid combination of operators and
operands.
OR
An arrangement of identifiers, literals and operators that can be evaluated
to compute a value.
The types of expressions are
1. Arithmetic Expression: It is a valid combination of arithmetic operators
and operands.
There are three types
1) Integer Mode: These expressions are formed using integer values,
constants and arithmetic operators.
Ex: 20+7, 20/5 etc.
2) Real Mode: These expressions are formed using real values,
constants and arithmetic operators.
Ex: 9.8+7.6, 25.0/5.0 etc
3) Mixed Mode: These expressions are formed using real and integer
values, constants and arithmetic operators.
Ex: 25/5.0, 7%5+10 etc
2. Relational Expression: It is a valid combination of relational operators
and operands. These expressions evaluate to true or false value.
Ex: 3<7, 21>=10 etc
3. Logical Expression: It is a valid combination of relational operators,
logical operators and operands. Using logical operators, multiple
conditions can be checked.
Ex: if (marks>=35) && (marks<=100)
(a>b) || (b>c)