Here is a C++ program to find address of elements in array
SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
int a1[20],num;
cout<<"How many elements to be stored (max 20) : ";
cin>>num;
cout<<"Enter elements of array a1 : ";
for(int i=0;i<num;i++)
cin>>a1[i];
cout<<"Elements : Address"<<endl;
for(int i=0;i<num;i++)
cout<<"a["<<i<<"] = "<<a1[i]<<" : "<<int(&a1[i])<<endl;
return 0;
}
using namespace std;
int main()
{
int a1[20],num;
cout<<"How many elements to be stored (max 20) : ";
cin>>num;
cout<<"Enter elements of array a1 : ";
for(int i=0;i<num;i++)
cin>>a1[i];
cout<<"Elements : Address"<<endl;
for(int i=0;i<num;i++)
cout<<"a["<<i<<"] = "<<a1[i]<<" : "<<int(&a1[i])<<endl;
return 0;
}
Any questions regarding to program please write in comments.
No comments:
Post a Comment