4,592 views
4 votes
4 votes

The following program

#include<stdio.h>
main ( )
{
int abc ( );
abc ( );
(*abc) ( );
}
int abc ( )
{ printf (“come”);}


(a) results in a compilation error (b) prints come come
(c) results in a run-time error (d) prints come

1 Answer

2 votes
2 votes

It will print come come

At first main() starts executing.Firstly int abc() declaration inside main().Then abc() is call by value, but it will not give any effect in printing. (Because call by value will just create problem when we need function to return value in main(), Here no need to returning any value in main() ).So, abc() will just print come after the first call,

In line 6 when the 2nd (*abc)() called, it is calling by pointer. So, when (*abc)() called abc() function, first one is pointer to abc() function definition. So, here another come will be printed.

The function name is the address of the function and it can be assigned to a function pointer. In the given code

(*abc)=abc

is similar to write int *x=&y

We can also write a new code by pointer to a function (for better understanding) like this which shows (*abc)(). function just a pointer to another integer function.

            #include<stdio.h>
            int X();
                int main()
                {
                int (*abc)();
                int X();
                 abc=X;
                (*abc)();
     
                }
                int X()
                { printf("come");}

So, final answer will be come come

https://www.quora.com/What-is-the-difference-between-function-pointer-and-pointer-to-a-function

https://denniskubes.com/2013/03/22/basics-of-function-pointers-in-c/

edited by

Related questions

0 votes
0 votes
1 answer
1
SSR17 asked Feb 29
204 views
#include <stdio.h int main() { int i = -1; int x = (unsigned char)i; printf("%d", x); return 0; }output is 255 , but please explain how
2 votes
2 votes
1 answer
4
rupamsardar asked Aug 30, 2023
466 views
#include <stdio.h int f(int x) { if(x%2==0) { return f(f(x-1)); } else return (x++); } int main() { printf("%d",f(12)); ret...