C Programming - Declarations and Initializations - Discussion
Discussion Forum : Declarations and Initializations - Yes / No Questions (Q.No. 5)
5.
Is it true that a function may have several declarations, but only one definition?
Answer: Option
Explanation:
Yes, but the function declarations must be identical.
Example:
#include<stdio.h>
void Display();
void Display();
void Display();
void Display()
{
printf("Weclome to IndiaBIX.com..!");
}
int main()
{
Display();
return 0;
}
//Output:
Weclome to IndiaBIX.com..!
Discussion:
12 comments Page 1 of 2.
Rovin varshney said:
1 decade ago
What is the advantages of several declaration.
Yogesh Agrawal said:
1 decade ago
There is no advantage of several declaration. Just it does not give any error.
Shankar said:
1 decade ago
But incase of functional overloading, same fn add () , can be used to add string, number etc, here fn defn is more than once, then how can we say, for same fn, only one defn?but here fn arguments differ for two fns, but fn name is same only, then how can we say, the same fn cannot be declared more than once.
Rupinder said:
1 decade ago
There is no such advantage for this consecutive declaration, but declaration at different part of program (calling) has sever advantage according to program requirement.
Ramesh K said:
1 decade ago
Hi Guys,
Several declaration with different argument will have different functions. Above question answers might be no also. Because we can active the polymorphism concept using this technique only.
Several declaration with different argument will have different functions. Above question answers might be no also. Because we can active the polymorphism concept using this technique only.
Madhuri said:
1 decade ago
Can any elaborate more about it?
Shreyas said:
1 decade ago
We can have different definitions for the same function also, if we pass different arguments.
Ace said:
1 decade ago
Is there in any context of "extern" with which we can answer this question?
Krishma said:
9 years ago
Since it says multiple declarations it can form any prototype which should be the answer No.
Because that is ideally not allowed and that different declaration only means function overloading which has a different definition for each.
Because that is ideally not allowed and that different declaration only means function overloading which has a different definition for each.
Digimado said:
5 years ago
How we know that there is the same declaration.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers