In our first program , we saw how to print something . But thats not it , programming doesnt stick only to printing few text !!! Lets take an example , if you wanna add 2 numbers you can do it in two ways :
1.Simply printing it i.e
cout<<“sum”<<2+3;
2. By storing the sum in a variable and then printing it
i.e
int s=0;
s=1+3;
cout<<s ;
here s is a variable , variable is something that stores some value . And its value can b changed during the execution of our program !!
example
s=s+1;
here we modified the value of s ;
i.e if s=4;
then now it will be 5.
DATATYPE
In the above example , we saw there was something weird written …….”int”… This int is a data type , as the name suggests data type tells about what kind of data that will be used in our program . There are many different types of data types :
1. int – integer type
2. float – decimal type
3.char- character type (it stores only 1 character)
4.boolean (takes 0 or 1)
Whenever we define a variable , it is done with the help of a data type otherwise errors will be generated.Now when a variable is defined , it doesnt take any memory space , when the program is executed then these variables take memory space.Different datatypes occupies differnt size
int [2 bytes]
float[4 bytes[
char[1 byte]
Register/Subscribe with us to learn more about C++…