Someone will probably respond before i'm done, but here's my reply anyway :
I think you should work work with subscripts in your program rather than pointers.
I don't usually make programs for people who need help , but i had to remake your program to show you an easier way to do it (along with comments) :
#define N 5 // use captial letters for #define constants
// to seperate them from the variables you declare
// within your program.
int foo(const int *); // use const to prevent altering your
// array's contents
int main(void) // main should ALWAYS return an int
int arr; // array
int i; // subscript (or array index)
printf("Enter 5 numbers : \n");
for(i=0; i<N; i++)
i = foo(arr); // send the adress of the first element
// of "arr" to foo
printf("\n%d\n", arr[i]); // print the value found (or first
// element if not found)
return 0; // this means program terminated sucessfuly
int foo(const int *arrP)
int k; // another subscript
// we treated our pointer just like an array.
for(k=0; k<N; k++)
// if an element is less than zero , return its location
if(arrP[k] < 0)
// or else return the location of the first element
there you go.
I didn't compile your program , but i guess the reason it returns a pointer to the first element is this piece of code :
this means if any element is NOT less than zero then return a pointer to the first element. So if your second element had a positive value for example, it would ignore the 'if' statement and go to the 'else' wich returns the first element's location. This is why i seperated the last 'return' from the loop.
Hope this helps
*EDIT* you guys were too fast