Monday, 24 October 2022

Fundamentals of Variables

  Keywords:







Variables:

 

Every variable must have:

💬Data type
💬Name 
💬Size
💬value

Variable declaration:


Variable declaration:

Codes:

Data type sizes:


#include<iostream>
using namespace std;
int main()
{
cout<<"\nMemory Size of Data Types\n";
cout<<"Size Of short:"<<sizeof(short)<<endl; cout<<"Size Of short int:"<<sizeof(short int)<<endl;
cout<<"Size Of int:"<<sizeof(int)<<endl;
cout<<"Size Of Long int"<<sizeof(long int)<<endl;
cout<<"Size Of Long"<<sizeof(long)<<endl; cout<<"Size Of long long:"<<sizeof(long long)<<endl; cout<<"Size Of float:"<<sizeof(float)<<endl;
cout<<"Size Of double"<<sizeof(double)<<endl; cout<<"Size Of long double"<<sizeof(long double)<<endl;
}


Variable decleration:


#include<iostream>
using namespace std;

int main()
{

int age;  //variable declaration
age =30;  //assignment operation on variable age

int marks = 100; // variable definition i.e variable created as well as initialized

cout<<"age:"<<age<<" marks:"<<marks<<endl;


//overwriting previous values of variables age and marks

age = 31;
marks=98;

cout<<"Displaying new values of age and marks"<<endl;
cout<<"age:"<<age<<" marks:"<<marks<<endl;

}












No comments:

Post a Comment

Fiver Account

 Fiver Account: https://www.fiverr.com/s/bPlNbN