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.
Govind said:
1 decade ago
Please, can anyone explain fun(main) will not go for infinite?
SSFD said:
1 decade ago
The address of main was passed just to complicate things and test whether you can understand the concept or not. In actual program none is going to do so.
Robin said:
1 decade ago
If we are not using the address of main function then what is the need for passing it?
Tinky said:
1 decade ago
Adding to @Raju comment:
If I pass any arguments on the calling functions then how will the function work and what is the use of it?
Passing a variable (by value or reference) has practical implementations in Projects, but what is the use of passing a function? Can we access the variable of function if we pass them as argument?
Thanks in advance,
If I pass any arguments on the calling functions then how will the function work and what is the use of it?
Passing a variable (by value or reference) has practical implementations in Projects, but what is the use of passing a function? Can we access the variable of function if we pass them as argument?
Thanks in advance,
Asha said:
1 decade ago
What is the meaning of fun(main) ?
XYZ said:
1 decade ago
Can we write like these :fun(main) ?
Is it valid? How?
Is it valid? How?
Shravana said:
1 decade ago
Sorry guys. I can't understand the line: int fun(int(*p)()). Can anyone explain it?
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:
2 decades 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