function.....

#include<stdio.h>
#include<conio.h>
float * display(int,int);
int max=5;

int main(){
clrscr();
float *(*ptr)(int,int);

ptr=display;

(*ptr)(2,2);
printf("%d",ptr);

printf("\n%u",ptr);

getch();
return 0;
}

float * display(int x,int y){
float f;
f=x+y+max;
return &f;
}

output = 709

why is it so...???
1. Don't return pointers to local objects. The objects go out of scope when the function returns, so the pointers become invalid.
2. You are printing the function pointer, not the result of the call.
Topic archived. No new replies allowed.