C++ Data Types
In
this section, we will learn about basic data types such as int, float, char,
etc. in C++ programming with the help of examples.
In
C++, data types are declarations for variables. This determines the type and
size of data associated with variables. For example,
int age = 13;
Here, age is
a variable of type int. Meaning, the variable can only store integers of
either 2 or 4 bytes.
C++
Data Types
The table below shows the fundamental data
types, their meaning, and their sizes (in bytes):
C++ Operators
Operators
are symbols that perform operations on variables and values. For example, + is
an operator used for addition, while - is an operator used for
subtraction.
Operators
in C++ can be classified into 6 types:
1. Arithmetic Operators
2. Assignment Operators
3. Relational Operators
4. Logical Operators
5. Bitwise Operators
1.
C++ Arithmetic Operators
Arithmetic operators are
used to perform arithmetic operations on variables and data. For example,
a + b;
Here,
the + operator is used to add two variables a and b.
Similarly there are various other arithmetic operators in C++.
2.
C++ Assignment Operators
In C++, assignment
operators are used to assign values to variables. For example,
// assign 5 to a
a = 5;
Here,
we have assigned a value of 5 to the variable a.
3.
C++ Relational Operators
A relational operator is used to check the relationship
between two operands. For example,
// checks if a is greater than b
a > b;
Here, > is
a relational operator. It checks if a is greater than b or
not.
If
the relation is true, it returns 1 whereas if the
relation is false, it returns 0.
4. C++ Logical Operators
Logical
operators are used to check whether an expression is true or false.
If the expression is true, it returns 1 whereas if
the expression is false, it returns 0.
5.
C++ Bitwise Operators
In
C++, bitwise operators are used to perform operations on individual bits. They
can only be used alongside char and int data types.
0 Comments