Consider the following three, C functions:
[P1]int*g(void);
{
int x = 10;
return(&x);
}
[P2]int*g(void);
{
int*px;
*px = 10;
return px;
}
[P3]int*g(void);
{
int*px;
px=(int*)malloc(size of(int));
*px = 10;
return px;
}
Which of the above three functions are likely to cause problems with pointers?
Function pointers can be useful when we want to create callback mechanism, and need to pass address of a function to another function. They can also be useful when we want to store an array of functions, to call dynamically.
The following three, C functions:
[p1]int*g(void);
{
int x = 10;
return(&x);
}
[p2]int*g(void);
{
int*px;
*px = 10;
return px;
}
[p3]int*g(void);
{
int*px;
px=(int*)malloc(size of(int));
*px = 10;
return px;
}
Output:-
Only p1 and p2.