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 1 of 2.
Rohan said:
7 years ago
@ALL.
Step 1: void display(int (*ff)()); ->a display is a function with a arguement as [*ff pointer function which is integer ] and its returns type of the function (display ) is void ..
int show();
Step 2: a function[ show() ] is declared as integer.
int (*f)();
Step 3: a pointer function [*f()] is declared as f.
f = show();
Step 4: It should store the content of show() function
display(f);
Step 5: displays the content of f.
void display(int (*ff)())
{
(*ff)();
}
Step 6: definition of the function[display]
int show()
{
printf("IndiaBIX");
}
Step 7: It will define the function show() and print IndiaBix.
Step 1: void display(int (*ff)()); ->a display is a function with a arguement as [*ff pointer function which is integer ] and its returns type of the function (display ) is void ..
int show();
Step 2: a function[ show() ] is declared as integer.
int (*f)();
Step 3: a pointer function [*f()] is declared as f.
f = show();
Step 4: It should store the content of show() function
display(f);
Step 5: displays the content of f.
void display(int (*ff)())
{
(*ff)();
}
Step 6: definition of the function[display]
int show()
{
printf("IndiaBIX");
}
Step 7: It will define the function show() and print IndiaBix.
(1)
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.
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.
Disha said:
8 years ago
int (*f)();
f = show;
f is a pointer to the function replace f by show int (*show)(); So it was correct I guess.
f = show;
f is a pointer to the function replace f by show int (*show)(); So it was correct I guess.
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.
Priya said:
9 years ago
But show is a function, then f = show how it can be possible?
It should be f=show(). So, here is an error.
It should be f=show(). So, here is an error.
Dave said:
7 years ago
Technically, the function show() should return a value, since it is declared [int show()].
Naseeb said:
1 decade ago
f = show means assigning the address of the function show to the 'f' variable.
Jessie said:
1 decade ago
f=show is wrong.it should be replaced with show().then how the result came?
Gaurav said:
9 years ago
Show function has not been declared. Then how the error will not generate?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers