Variable in C++, how to declare variable in C++,int float,char
Variable in C++
What is the variable?
This question arises in our mind.Variable in basically a memory resolved in RAM and it can store the value which is assign to it. Note: Every variable has its own data type. For example we need to store the integer 2 and 3 in C++ so in first step we will declare two variables for which the memory will reserved in the Ram.
Example
int a; int b;These are two variables which we have defined. In second step we will assign values to these variables.
a=2; b=3;These values then stored in the reserved memory in the RAM. We can directly define a variable and assign value to it in one step.
For example.
int var1=3; float result= 5;We can also directly define more than one variable in the single line.
int a,b,c;Examples
#include<iostream.h>
int main( )
{
int a;
float b;
char c;
a=2;
b=3.14;
c=’A’;
cout<<a;
cout<<b;
cout<<c;
return 0;
};
Output :
2 3.14 A Example
#include<iostream.h>
int main( )
{
int a=3;
int b=2;
int c;
c=a+b;
cout<<c;
return 0;
};
output:5


