Sunday, 13 March 2016

C++ Program To Print Address of An Array Using Pointer

Problem:- Address of an array using pointer in c++ or C++ Program To Print Address An Array Using Pointer or c program to display array elements using pointers or c++ program to display array elements using pointers or write a c++ program to display address of elements of an array using both array and pointers or c++ program to print address of an array or address of array element in c or address of array elements in c++.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Explanation:- address of array element in c++, we have to print the address of an array(an array 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 "address of" or "&" operator. Ths "&" operator returns the address of a variable in a memory location. or we can do this by using a pointer for that we have to transfer all array elements to pointer one by one and print the pointer value as we know that 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 pointer.

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- If this post is beneficial for you and you want Updates for New post then please like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.


Solution:-

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

int main()
{
/*visit - www.programmingwithbasics.com*/
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 An Address Using An Arrays";    
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 An Address Using Pointers";
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;
}


Output:-

Address of an array using pointer in c++


You May Like This

1. C++ Program To Convert A Lower Case To Upper Case

2. C++ Program To Print Reverse A Sentence

3. C++ Program To Print A Full String Input By Keyboard

4. C++ Program For Reading A No. From File And Sum Of No. Line By Line Using File

5. C++ Program For Count A Character In File Using File

6. C++ Program To Display The List Of Current Directory/Folder Using File

7. C++ Program For Copy One File To Another Using File Handling

8. C++ Program To Merge Two File Into the Third File Using File Handling

9. C++ Program For Count A Words In Given String Even Enter No Of Space's Between String

10. C++ Program To Print A Pascal Triangle


Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment