AD1

Saturday, 14 January 2017

Pointers and 2D arrays

Assume you have 2D array S[2][4]={{1234,56},
{1212,33},
{1434,80},
{1312,78}};
write a C program to print all the values and their corresponding addresses of this array
using pointers

#include "stdio.h"
int main()
{
int s[4][2] ={
{1234,56},
{1212,33},
{1434,80},
{1312,78}
};
int *p=&s[0];// pointer to array
for(int i=0;i<=3;i++)
{
printf("Start Address of %d th 1-D array = %d\n",i,&s[i]);
for(int k=0;k<=1;k++)
{
printf("address of elemnt %d in %d th 1-D array %d \t and its value = %d\n",k,i,p,*p);
p++;
}
}
return 0;
}
view raw 2d.c hosted with ❤ by GitHub

No comments:

Post a Comment