Wednesday, 2 July 2014

C++ program to illustrate pointers and multidimensional array


Here is a C++ illustrate pointers and multidimensional array


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    int x[2][3]={10,20,30,
                 40,50,60,};
    int *p;
    p=x[0];
    cout<<"Accessing 1st element of 0 row : "<<*(p+0*3+0)<<endl;
    cout<<"Accessing 2nd element of 0 row : "<<*(p+0*3+1)<<endl;
    cout<<"Accessing 3rd element of 0 row : "<<*(p+0*3+2)<<endl;
    cout<<"Accessing 1st element of 1 row : "<<*(p+1*3+0)<<endl;
    cout<<"Accessing 2nd element of 1 row : "<<*(p+1*3+1)<<endl;
    cout<<"Accessing 3rd element of 1 row : "<<*(p+1*3+2)<<endl;
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment