CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

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?

A
Only P3
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
Only P1 and P3
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
Only P1 and P2
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
D
P1, P2 and P3
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is C Only P1 and P2

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.



flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Animal Tissues
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon