0% found this document useful (0 votes)
6 views2 pages

Pointerto 2 D

The document is a C program that demonstrates the use of a 2D array and pointers. It initializes a 3x3 array, prints its elements and their addresses, and shows how to access rows and elements using a pointer to the array. The program also prints specific values from the array using pointer arithmetic.

Uploaded by

shiva_pr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Pointerto 2 D

The document is a C program that demonstrates the use of a 2D array and pointers. It initializes a 3x3 array, prints its elements and their addresses, and shows how to access rows and elements using a pointer to the array. The program also prints specific values from the array using pointer arithmetic.

Uploaded by

shiva_pr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include<stdio.

h>

int main(){
int a[3][3]={ 1,2,3,4,5,6,7,8,9};
int i,j;
int (*p)[3];
printf("Given array elements : \n");
for( i=0;i<3;i++)
{
for( j=0;j<3;j++)
printf("%d ",a[i][j]);
printf("\n");
}

printf("Address of individual elements : \n");


for( i=0;i<3;i++)
{
for( j=0;j<3;j++)
printf("%p ",&a[i][j]);;
printf("\n");
}

p=a;//initialization

printf("\nAddress of first row = &a[0] :


%p\n",&a[0]); //address of first row
printf("Address of first row using pointer = p :
%p\n",p); //pointer to first row

printf("Address of ith row = &a[1] : %p\n",&a[1]);


printf("Address of ith row using pointer = p+1 :
%p\n",p+1);

printf("\nAddress of first element in ith row =


*(p+1) : %p\n",*(p+1)+0);
printf("Address of jth element in ith row =
*(p+1)+0 : %p\n",*(p+1)+0);
printf("Address of jth element in ith row =
*(p+1)+1 : %p\n",*(p+1)+1);
printf("Address of jth element in ith row =
*(p+1)+2 : %p\n",*(p+1)+2);
printf("Value at a[0][2] = *(*(p)+2) :
%d\n",*(*(p)+2));
printf("Value at a[1][2] = *(*(p+1)+2) :
%d",*(*(p+1)+2));

You might also like