Wednesday 20 February 2013

pointer to array


#include<stdio.h>
#include<conio.h>
int highest(int *ptr,const int row,const int col);
void main()
{
int *ptr;
int temp[3][4]={3,4,2,6,5,8,9,12,0,4,7,10};
ptr=&temp[0][0];
printf("%d",highest(ptr,3,4));
getch();
}
int highest( int *ptr,const int row,const int col)
{
int h=0;
for(int i=0;i<row;i++)
for(int j=0;j<col;j++)
if(*(ptr+i*col+j)> h)
h=*(ptr+i*col+j);
return h;
}

NOTE: here *(ptr+i*col+j)=temp[i][j].
program finds the highest value element of 3x4 array. 

1 comment:

  1. Lucky Club: Live Dealer Casino Site & Promotions
    Lucky Club is an online casino where you can experience the best in live casino games from the best of 카지노사이트luckclub the best providers from all over the world.

    ReplyDelete