Variables & Data Types in C++ | Topic 3 | VU Insider



Variables in c++ are like containers which are used to store data values. There are different type of variables used for declaration.

How to declare a variable in C++?

We can declare any variable by using the following syntax;
type variable = value;code-box

Data Types in C++

There are few data types used in c++:
  • int
  • short
  • long
  • float
  • double
  • char
  • bool

int Data Type

It is used to store whole numbers (integers) occupying 4 bytes of memory.

Example:
int a;
int b;
code-box


Or
int a, b;
a = 3;
b = 4;
code-box


short Data Type

It is used to store small whole numbers occupying 2 bytes of memory. The range is from -32768 to 32767.

Example:
short x;
x=30; code-box


long Data Type

It is used to store a very long whole numbers.

Example:
long x;
x=302938203938 code-box


float Data Type

It is used to store real numbers with decimal points occupying 4 bytes of memory.

Example:
float x;
x=32.45; code-box

double Data Type

It is used to store large real numbers occupying 8 bytes of memory.

Example:
double x;
x=53632.2424 code-box

char Data Type

It is used to store characters like a, b, c etc. The size is 1 byte.

Example:
char x;
x= 'Ali'; code-box

bool Data Type

It is used to store boolean true or false values. It's memory size is 1 byte.

Example:
bool x;
x= true; code-box

Post a Comment

Previous Post Next Post