You are on page 1of 3

Page 1 of 3

TASK #1:
What is Variable? Why we use variable in program?
SOLUTION:
In C++ programming, A variable is a name which is associated with a value that can be changed. For
example, when I write int num=20; here variable name is num which is associated with value 20, int
is a data type that represents that this variable can hold integer values. Variables play a significant role
in constructing a program, storing values in memory, and dealing with them.
Task #2:
Create the source file and observe the output of the following program?
#include<iostream.h>
main ( )
{
int a, b;
a = 10;
b = 4;
a = b;
b = 7;
cout << "a :";
cout << a;
cout << " b :";
cout << b;
}

SOLUTION:
Page 2 of 3

TASK #3:
Create the source file and observe the output of the following program?
#include <iostream.h>
main ()
{
int a;
cout <<“Enter the value of a”<<endl;
cin>>a;
cout<<”The value of a is = “<<a;
}

SOLUTION:

TASK #4:
Write a program using different variables, initialize the values of variables in the program
and then display the values.
SOLUTION:
#include <iostream>
using namespace std;
int main ()
{
char a='K';
int b=10;
float c=20.3;
cout <<a<<", "<<b<<", "<<c;
}
Page 3 of 3

TASK #5:
Write a program that takes the variable value from user and then display that value.
SOLUTION:
#include <iostream>
using namespace std;
int main ()
{
int x;
cout<<"Enter any number: ";
cin>>x;
cout<<"You entered: "<<x;
}
TASK #6:
Write a program to find the number of bytes occupied by various data types using
sizeof function.
int a;
float b;
long int c;
double d;
char e;

SOLUTION:
#include <iostream>
using namespace std;
int main ()
{
int a; float b; long int c; double d; char e;
cout<<"Size of (int a): "<<sizeof(a)<<" Byte\n";
cout<<"Size of (float b): "<<sizeof(b)<<" Byte\n";
cout<<"Size of (long int c): "<<sizeof(c)<<" Byte\n";
cout<<"Size of (double d): "<<sizeof(d)<<" Byte\n";
cout<<"Size of (char e): "<<sizeof(e)<<" Byte\n";
}

Prepared By: Khawar Khalil

You might also like