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");
}
Discussion:
17 comments Page 2 of 2.
Naseeb said:
1 decade ago
f = show means assigning the address of the function show to the 'f' variable.
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.
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.
Jessie said:
1 decade ago
f=show is wrong.it should be replaced with show().then how the result came?
Amol shanbhag said:
1 decade ago
Simple function call for the function show()
Rahul said:
1 decade ago
Can anyone explain why f=show is used?
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.
//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.
Prudhvi said:
1 decade ago
Somebody explain this please.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers