C++ Programming - Functions - Discussion

Discussion Forum : Functions - General Questions (Q.No. 1)
1.
Which of the following function prototype is perfectly acceptable?
int Function(int Tmp = Show());
float Function(int Tmp = Show(int, float));
Both A and B.
float = Show(int, float) Function(Tmp);
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
19 comments Page 2 of 2.

Prasadkumar said:   1 decade ago
--------------------------------------------------------------------
[B]. float Function(int Tmp = Show(int, float));

In above option there is type but no arguments in show().

Actually the function definition is like this:

returntype funname(type arg1,type arg2) {
body
}
-----------------------------------------------------------

[D]. float = Show(int, float) Function(Tmp);

in the above function also same error id there.
(1)

Sree said:   1 decade ago
In the case of function prototype I think the type of the arguments are to be specified not the variable name, here return type should be specified.

Karuppusamy said:   1 decade ago
The statement in A only matches with the syntax of a function declaration.

Seema said:   1 decade ago
B is incorrect as how do we send the arguments of function show.
(1)

Sunchuramya said:   1 decade ago
First we should know the logic's to execute a program.
(2)

Vada said:   1 decade ago
First know the logic's to execute.
(2)

Durgesh said:   10 years ago
float = Show(int, float) Function(Tmp);
(3)

Kmp said:   9 years ago
Parameters should not be initialized in the function argument.
(3)

Sharon Rajendra Manmothe said:   10 months ago
Function Prototype: A function prototype declares a function's name, return type, and parameter list. It informs the compiler about the function's existence and its signature.

Default Argument: A default argument is a value that is automatically assigned to a parameter if no argument is provided during the function call.  
In the given prototype:

int Function(int Tmp = Show()):
This declares a function named Function that returns an integer.

It takes an optional integer parameter Tmp. If no argument is provided for Tmp, the default value is obtained by calling the Show() function.

Why the other prototypes are invalid:
float Function(int Tmp = Show(int, float)):
The default argument Show(int, float) is incorrect. A default argument must be a constant expression or a function call that doesn't require any arguments.
float = Show(int, float) Function(Tmp);:

This is not a valid function prototype. It's syntactically incorrect and doesn't follow the standard function declaration format.
(2)


Post your comments here:

Your comments will be displayed after verification.