C++ Programming - Functions - Discussion
Discussion Forum : Functions - General Questions (Q.No. 1)
1.
Which of the following function prototype is perfectly acceptable?
Discussion:
19 comments Page 1 of 2.
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.
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)
Kmp said:
9 years ago
Parameters should not be initialized in the function argument.
(3)
Durgesh said:
10 years ago
float = Show(int, float) Function(Tmp);
(3)
Vada said:
1 decade ago
First know the logic's to execute.
(2)
Sunchuramya said:
1 decade ago
First we should know the logic's to execute a program.
(2)
Seema said:
1 decade ago
B is incorrect as how do we send the arguments of function show.
(1)
Karuppusamy said:
1 decade ago
The statement in A only matches with the syntax of a function declaration.
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.
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.
[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)
Shahzada said:
1 decade ago
Yes option A is correct answer because in A function prototyping show function is called but in option B in prototyping of one function another prototyping is given which is not according to the syntax of function prototyping because return typing is not given.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers