Lab Manual 03 - Data Types.
Lab Manual 03 - Data Types.
Lab # 03.....................................................................................................................2
3.1 Objective:............................................................................................................2
3.2 Scope:..................................................................................................................2
3.3 Useful Concept:..................................................................................................2
3.4 Examples:...........................................................................................................3
3.5 Lab Exercise.......................................................................................................7
3.6 Home Work.........................................................................................................7
Lab Rubrics
3.2Scope:
The student should know the following:
Problem Solving
Different data types of C and their Use.
Declaring Variables
Standard Input and Output
Writing Complete Programs
3.3Useful Concept:
A list of basic data types of C++, number of bytes used to store these data types in memory of
computer system is:
3.4 Examples:
int main ()
{
int a = 5; // initial value: 5
int b(3); // initial value: 3
int c = 2; // initial value: 2. Also try int c{2};
int result; // initial value undetermined
a = a + b; result = a
- c; cout << result;
return 0;
}
int main ()
{
string myname;
myname = " Abbas Khalid"; cout
<< myname;
return 0;
}
return 0;
}
int main ()
{
char x, y ;
int z ; x =
'a' ;
y = 'b' ;
z=x+y; //Add the assci value of 'a' with assci value of 'b'. cout<<z<<endl;
return 0;
}
Here’s the program’s output: 195
Example 3.6: This program illustrates the use of sizeof() function which is used
to find the memory space allocated for each C++ data type.
#include <iostream>
#include <climits> using
namespace std; int main ()
{
int a; char b;
#include
<iostream> using
namespace std; int
main()
{
int n = 54;
cout << std::oct << "oct - " << n <<
'\n'; cout << std::dec << "dec - " <<
n << '\n'; cout << std::hex << "hex -
" << n << '\n';
return 0;
}