Home
Aptitude
Categories


Home » C++ programs

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



In this C++ program, we are going to declare different types of pointer variables, printing their occupied size, values and addresses.
Submitted by IncludeHelp, on May 04, 2018

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

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 and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.