4,645 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
2 answers
1
Debargha Mitra Roy asked Apr 16
140 views
#include <stdio.h int main() { int a[3] = {1, 3, 5, 7, 9, 11}; int *ptr = a[0]; ptr += sizeof(int); printf("%d", *ptr); return 0; }(Assume size of int to be $2$ bytes.)T...
0 votes
0 votes
2 answers
3
Debargha Mitra Roy asked Apr 10
159 views
What is the output of the below code?#include <stdio.h void main() { static int var = 5; printf("%d ", var ); if (var) main(); }a. 1 2 3 4 5b. 1c. 5 4 3 2 1d. Error
2 votes
2 votes
1 answer
4
SSR17 asked Feb 29
284 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