- 1

Assignment, Here pointer is assigned to function or function is assigned to pointer ..??

void (*funptr)(int); /* function pointer */ funptr = say_hello; /* pointer assignment */

14th Jul 2019, 5:24 PM
Krishna Kumar
Krishna Kumar - avatar
6 Antworten
+ 3
Function is assigned to a pointer
14th Jul 2019, 5:42 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 3
Yes you are correct, what actually happens is the function cannot be assigned to a pointer variable because it is a piece of executable code, so that's why function pointer will get assigned to the function rather than the other way around.
14th Jul 2019, 6:08 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 3
Nope, say_hello is a function and funptr is a variable. It's not possible to assign any value or variable to a function (a piece of executable code). Assigning function pointer to some function means that the function pointer has the address of that specific function, which means that function pointer is just pointing to that specific function.
14th Jul 2019, 8:32 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
nAutAxH AhmAd But in function pointer topic of C in SoloLearn it is written "The following short program declares a function, declares a function pointer, assigns the function pointer to the function, and then calls the function through the pointer" ....??it is saying pointer is assigned to a function..?
14th Jul 2019, 5:46 PM
Krishna Kumar
Krishna Kumar - avatar
+ 1
15th Jul 2019, 12:39 AM
Krishna Kumar
Krishna Kumar - avatar
0
But if function pointer will get assigned to the function shouldn't it be like say_hello=funptr; ?
14th Jul 2019, 6:15 PM
Krishna Kumar
Krishna Kumar - avatar