2-Dimensional Array through pointer using C++
//Two Dimensional Array through Pointer in C++
#include<iostream>
using namespace std;
int main()
{
int arr[2][3]={
{10,20,30},
{40,50,60}};
int* ptr;
ptr=(int*)arr;
cout<<sizeof(int);
cout<<endl<<"Values of the array:";
for(int i=0;i<6;i++)
cout<<*(ptr+i)<<" ";
cout<<endl<<"Now Enter 5 values to array:"<<endl;
for(int i=0;i<6;i++)
{
cin>>*(ptr+i);//because cin takes variable name to write not address
}
cout<<endl<<"Again Values of the array:";
for(int i=0;i<6;i++)
cout<<*(ptr+i)<<" ";
return 0;
}//end of main
Comments
Post a Comment