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
*/
#include <iostream>
int main()
{
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;
return 0;
}
$ a.out Datatype Pointer Size int 4 char 4 long 4 float 4 double 4
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Related Posts:
- Apply for Computer Science Internship
- Check C++ Books
- Practice Programming MCQs
- Check Programming Books
- Check Computer Science Books