Quick links: C-Tricks HR Interview Que. Code Snippets C Programs C++ Programs Java Programs PHP Examples

Home » Code Snippets » C/C++ Code Snippets

C++ - Print the size of different type of pointers along with value addresses

By: Priya Kaushal On 23 DEC 2016

Here, we will learn how we can print the size of different type of pointer variables in c++ programming language?

We are using sizeof() operator to get the size of variables.

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;	
}

Sponsored Links



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 iptr, cptr 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).


COMMENTS

Solved programs


Sponsored Links


Most viewed pages


Featured posts
C Tips and Tricks

Keywords (like Linux, Java, Oracle etc) used in this website are the trademarks of their respective owners/company. This website is not affiliated to any company. The tutorials are designed by includehelp Team with the help of well known books and other online resources. These Tutorials are free for all, for learning purposes only. Enjoy learning:)
Copyright © 2015 - 2016. All Rights Reserved.