Q:

C++ program to print the size of different types of pointers along with values and addresses

belongs to collection: C++ programs on various topics

0

C++ program to print the size of different types of pointers along with values and addresses

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the following program:

#include <iostream>

using namespace std;

int main()
{
	int   *iptr;
	char  *cptr;
	float *fptr;
	
	cout<<sizeof(iptr)<<","<<sizeof(cptr)<<","<<sizeof(fptr)<<endl;
	cout<<sizeof(*iptr)<<","<<sizeof(*cptr)<<","<<sizeof(*fptr)<<endl;	
	
	return 0;	
}

Output

8,8,8 
4,1,4

Program is compiled and executed on a 64 bits computer system architecture, that’s why the size of the pointer is 8.

In the above program, we are declaring 3 pointer variables iptrcptr and fptr of integer, character and float type.

 

And we are printing the size of these pointer variables along with the type of value (which will be stored in these the address stored in pointer variables).

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ programs on various topics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ program to declare an integer variable dynamic... >>
<< Count the created objects using static member func...