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
using namespace std;
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
Type : Size
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
If you wish to look at all C++ Programming examples, go to C++ Programs
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1,
- Chapterwise Mock Tests: Chapter 1,
, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry
. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms.
Stay connected with him at LinkedIn
Subscribe to his free Masterclasses at Youtube
& discussions at Telegram SanfoundryClasses