how to printf("Jai Baba Budhpri Ji\n") in function pointers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to printf("Jai Baba Budhpri Ji\n") in function pointers

I want to get the result Jai Baba Budhpri Ji

9th Apr 2020, 6:20 AM
kp kalia
kp kalia - avatar
1 Answer
+ 1
As you know function pointers are a special type of pointers that point to the functions: Function pointer syntax is as similar as declaring a function,like just it's declaration part which includes the returntype *func_name(arguments): Syntax: return-type (*func_name)(args);//brackets are to be observed!!It is a void (*)()type. *func_name=myfunc //where myfunc is my required function to which I want function pointer to point to. Actually when compiling starts for a called function the "compiled" is stored at an address an is called with that name: Ex: You can actually try to use something like this: #include<stdio.h> void myfunc(){ printf("Jai Baba Budhpri Ji\n"); } int main(){ void (*foo) (); foo=&myfunc; //this lets the pointer to point to the position of the stored value of the function foo(); //calling the pointer to do the action of the function //() Is put because of no arguments of the function return 0; } Note: You should not use printf(foo); This causes you to print the value of the address.
21st Apr 2020, 11:34 AM
Viroopaksh chekuri
Viroopaksh chekuri - avatar