Thursday, July 30, 2009

Finding highest value in array using pointer notation and calling a function in C language?

Hello ..


My examz are near can anyone tell me how to finding highest value in array using pointer notation and calling a function in C language ? I m having problem in solving this

Finding highest value in array using pointer notation and calling a function in C language?
Let the array be A[10].


Here A is the pointer to the first element in the array ie A[0].


Hence *A = Value of A[0].


Similarly *(A+i) = Value of A[i]


Now the following code will find the highest value in the array.


Note i am assuming the array has already been inputed.


main()


{


int max,i = 0;


max = *A


for(i=0;i%26lt;10;i++)


{


if(*(A+i)%26gt;max)


max = *(A+i)


}


printf("%d",max);


}





Regarding functions,


To call a function the syntax is : function_name ( Arguments );


Example :


#include%26lt;conio.h%26gt;


int sum (int a,int b); //Function declration


{


int sum;


sum=a+b;


printf("%d",sum);


}


main()


{


sum(5,3); //Function call.


}


Output will be 8.





Hope that helps.





Best Answer ?
Reply:Ah, damn it, I always lost marks due to pointers...


:-p


No comments:

Post a Comment