Print address of Array of numbers using pointer || Pointer || C++
In this, we are going to see how to print the Memory Address of a 'n' variables storing Integers in C++ Programming Language.

The Code given below can be used for TURBO C++ Compilers: -

//C++ program to print address of N integral numbers.

#include <iostream.h>
#include <conio.h>

void main()
{
    clrscr();
    int *p[1000], num[1000], n;

    cout << "Total number of terms:-\n";
    cin >> n;

    cout << "Enter the integral values:-\n";
    for (int i = 0; i < n; i++)
    {
        cin >> num[i];
    }

    for (int i = 0; i < n; i++)
    {
        p[i] = &num[i];
        cout << "Address of "<< num[i]<< " is:- "  << p[i] << endl;
    }
    getch();
}

//...........Coded by YASH ALAPURIA
  

The Code given below can be used for gcc/g++ Compilers: -

//C++ program to print address of N integral numbers.

#include <iostream>
#include <stdlib.h>
using namespace std;

int main()
{
    system("cls");
    int *p[1000], num[1000], n;

    cout << "Total number of terms:-\n";
    cin >> n;

    cout << "Enter the integral values:-\n";
    for (int i = 0; i < n; i++)
    {
        cin >> num[i];
    }

    for (int i = 0; i < n; i++)
    {
        p[i] = &num[i];
        cout << "Address of "<< num[i]<< " is:- "  << p[i] << endl;
    }
    return 0;
}

//...........Coded by YASH ALAPURIA
  
#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post