This C++ program prints the sizes of pointers to primitive datatypes like int, float, double and long. The size of the pointers is implementation dependent and should be same for every primitive datatype since it contains the same of data. The sizeof operator is used for determining the size of the datatypes.
Here is the source code of the C++ program which prints the sizes of the pointers to primitive datatypes like int, float, double and long. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
* C++ Program to Print Sizes of Pointers to Primitive Datatypes
int * ip;
long * lp;
char * cp;
float * fp;
double * dp;
std::cout << "Datatype " << "Pointer Size\n" << std::endl
<< " int" << std::setw(12) << sizeof(ip) << std::endl
<< " long" << std::setw(11)<< sizeof(lp) << std::endl
<< " char" << std::setw(11) << sizeof(cp) << std::endl
<< " float" << std::setw(10) << sizeof(fp) << std::endl
<< " double" << std::setw(9) << sizeof(dp) << std::endl;
Datatype Pointer 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