Monday, May 24, 2010

An error in c++ code???????

i want to know where's the error?, this is a program that get the max element in an array by using a pointer on the beginning of it and another on the last element


#include%26lt;iostream%26gt;


using namespace std;


int main()


{


int arr[5]={4,8,3,2,5};


double *ist,*last;


max(* ist,*last);


}


double max(double *begin,double*end)


{


double r=,x=0,y=0;


for(int i=0;*begin[i]%26lt;=end;i++)


r=begin[i];


x=begin[i+1] ;


if(x%26gt;r)


{


y=x;


}


else


{


y=r;


}


return y;


}

An error in c++ code???????
You have to initialize the pointers, and you have an int array, but your max function takes double*. So you either have to make the max function take int* or change the int array to a double array.





Once you fix the data type problem, here is how you initialize the pointers:





ist = %26amp;arr[0];


last = %26amp;arr[4]; // The element in the array since it's zero based indexing


No comments:

Post a Comment