Sunday, 13 March 2016

Write A C++ Program To Print Address Of Pointer Of An Array Using Pointer

#include
using namespace std;

int main()
{
    float a[5];
    float *ptr;
 
    cout << "Displaying address using arrays: "<    for (int i = 0; i < 5; ++i) {
        cout << "&a[" << i << "] = " << &a[i] <    }

    ptr = a;   // ptr = &a[0]
    cout<<"\nDisplaying address using pointers: "<< endl;
    for (int i = 0; i < 5; ++i) {
        cout << "ptr + " << i << " = "<    }

    return 0;
}

Output:-



No comments:
Write comments

Recommended Posts × +