cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
function.....
function.....
Sep 5, 2011 at 5:18am UTC
Tanuj31
(9)
#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...???
Sep 5, 2011 at 5:57am UTC
helios
(17574)
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.