This C++ Program which prints size of primitive datatypes. The program uses a library function sizeof( ) to print the size of the respective datatypes. The output streams are manipulated using the library functions setw( ) and setfill( ) defined in the header ‘iomanip’.
Here is source code of the C++ program which prints size of primitive datatypes. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Print Size of Primitive Datatypes
*/
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
char c;
int i;
long l;
float f;
double d;
cout << "Type : " << " Size" << endl;
cout << "char " << setw(5) << setfill(' ')
<< sizeof(c) << endl;
cout << "integer " << setw(2) << setfill(' ')
<< sizeof(i) << endl;
cout << "long " << setw(5) << setfill(' ')
<< sizeof(l) << endl;
cout << "float " << setw(4) << setfill(' ')
<< sizeof(f) << endl;
cout << "double " << setw(3) << setfill(' ')
<< sizeof(d) << endl;
}
$ g++ main.cpp $ ./a.out Type : Size char 1 integer 4 long 8 float 4 double 8
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Practice Programming MCQs
- Check Computer Science Books
- Check Programming Books
- Apply for C++ Internship
- Check C++ Books