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?
Yes
No
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.

Kannan said:   4 years ago
C doesn't support function overloading (it can only be achieved indirectly using pointers) and thus the answer provided is correct.

Divya Reddy said:   4 years ago
Based on return type of functions and the data types of parameters passed through the functions. We can know whether the function declarations are the same or not.

Digimado said:   5 years ago
How we know that there is the same declaration.

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.

Ace said:   1 decade ago
Is there in any context of "extern" with which we can answer this question?

Shreyas said:   1 decade ago
We can have different definitions for the same function also, if we pass different arguments.

Madhuri said:   1 decade ago
Can any elaborate more about it?

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.

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.

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.


Post your comments here:

Your comments will be displayed after verification.