C Programming - Complicated Declarations - Discussion

Discussion Forum : Complicated Declarations - Point Out Errors (Q.No. 3)
3.
Point out the error in the following program.
#include<stdio.h>
void display(int (*ff)());

int main()
{
    int show();
    int (*f)();
    f = show;
    display(f);
    return 0;
}
void display(int (*ff)())
{
    (*ff)();
}
int show()
{
    printf("IndiaBIX");
}
Error: invalid parameter in function display()
Error: invalid function call f=show;
No error and prints "IndiaBIX"
No error and prints nothing.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
17 comments Page 1 of 2.

Prudhvi said:   1 decade ago
Somebody explain this please.

Ranjit said:   1 decade ago
void display(int (*ff)());
//display is a function that returns
//void. Its argument is a pointer to a function returning int.

int show(); //prototype declaration.

int (*f)();
//f is a pointer to a function returning int.
//This is to be used as argument to display.
//display simply calls the function passed as argument.
//Observe that this program allows us to call a function as
//argument to another function. This is possible only using pointers.

Rahul said:   1 decade ago
Can anyone explain why f=show is used?

Amol shanbhag said:   1 decade ago
Simple function call for the function show()

Jessie said:   1 decade ago
f=show is wrong.it should be replaced with show().then how the result came?

Sampath said:   1 decade ago
To Jessie.

In the given program int (*f) () ;, it clearly indicates that f is function pointer.

Any function name holds address of that function as we see in array, there array name holds base address of that array.

There by.

F=show; means the function pointer f is initialized to address of the show function. There is no error in this statement.

Naseeb said:   1 decade ago
f = show means assigning the address of the function show to the 'f' variable.

Nivetha said:   10 years ago
How come f=show comes rights? Its an error.

Raja said:   10 years ago
What is the meaning of (*ff)();?

Amey said:   9 years ago
There should be an error option because the return type of function show() is int but it is not returning anything.


Post your comments here:

Your comments will be displayed after verification.