28/02/2023

Program to Print the Address of The Pointer of an Array In C++

Program to Print the Address of The Pointer of an Array In C++. Write a program in c++ to store n elements in an array and print the elements using a pointer. Write a c++ program to display the address of elements of an array using both array and pointers. address of array c++, we have to print the address of an array(an array of each variable of an array) or we have to display the memory location of each element of an array we can do this by adding the "address of" or "&" operator. The "&" operator returns the address of a variable in a memory location.

Program to Print the Address of The Pointer of an Array In C++

Address of an Array C++: We can do this by using a pointer for that we have to transfer all array elements to the pointer one by one and print the pointer value as we know a pointer is a variable that holds the address of another variable so each time in a Loop we assign the array value to a pointer and print the value of hold by the pointer. How to print array in C++.

Program to Print the Address of The Pointer of an Array In C++


#include <bits/stdc++.h>
using namespace std;

int main()
{
	/*Print the Address of The Pointer of an Array In C++*/

	int i, size;

	cout << "=======================================\n";
	cout << "Enter The Size of The Array ";
	cout << "\n=======================================\n";

	cin >> size;

	int array[size];
	int *ptr;

	cout << "=======================================\n";
	cout << "Enter The Elements Of An array";
	cout << "\n=======================================\n";

	for (i = 0; i < size; i++)
	{
		cin >> array[i];
	}

	cout << "==================================================\n";
	cout << "Displaying the Address of The Pointer of an Array";
	cout << "\n=================================================\n\n";
	for (i = 0; i < size; i++)
	{
		cout << "Address Of " << array[i] << " Using Array is ===> " << &array[i] << endl;
	}

	cout << "\n===============================================\n";
	cout << "Displaying the Address of The Pointer of an Array";
	cout << "\n===============================================\n";
	for (i = 0; i < size; i++)
	{
		ptr = &array[i];	// ptr = &a[0]
		cout << "Address Of " << array[i] << " Using Pointers is ===> " << ptr << endl;
	}

	cout << "\n========================================\n";
	return 0;
}

The Output of Address of The Pointer of an Array

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: