C Programming - Functions - Discussion
Discussion Forum : Functions - Find Output of Program (Q.No. 18)
18.
What will be the output of the program?
#include<stdio.h>
int fun(int(*)());
int main()
{
fun(main);
printf("Hi\n");
return 0;
}
int fun(int (*p)())
{
printf("Hello ");
return 0;
}
Discussion:
33 comments Page 2 of 4.
Niharika said:
9 years ago
As main call go there will recursion and no output.
Karthik said:
8 years ago
Why the infinite loop not exist when main was used?
Nagu said:
8 years ago
Why the infinite loop not exist when main was used?
The infinite loop does not exist because of the sub-function not recursive function so not infinite loop exists.
The sub-function print "hello" then come to the main function. Then print "hi" end the program.
So not confusing the pointer argument that only pass main program address that not used in sub-function.
Thanks.
The infinite loop does not exist because of the sub-function not recursive function so not infinite loop exists.
The sub-function print "hello" then come to the main function. Then print "hi" end the program.
So not confusing the pointer argument that only pass main program address that not used in sub-function.
Thanks.
Amruta said:
8 years ago
int (*p) () p is a function pointer which should point to a function taking no args and returning int.
Ram said:
7 years ago
Is this the correct way of passing any function into another function? Please explain.
Giridhar said:
6 years ago
Pointer function "*p() " which is referring to main is not invoking in "fun(int (*p) ()) ". So, the main() function is not invoked in recursive.
Suraj said:
6 years ago
Thanks for the valuable information @Govind.
Radhika said:
1 decade ago
We can access the variable of function. I think that is the advantage of passing a function as argument to another function.
Bagesh Kumar bagi said:
1 decade ago
First fun(main) come in the function and print the HELLO after that it will be return and it print the Hi
So that the finaly output is
hello hi..
So that the finaly output is
hello hi..
Raju said:
1 decade ago
If I passs any arguments on calling function then how will the function work.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers