C++ Programming - Functions - Discussion

Discussion Forum : Functions - General Questions (Q.No. 10)
10.
Which of the following statement is incorrect?
The default value for an argument can be a global constant.
The default arguments are given in the function prototype.
Compiler uses the prototype information to build a call, not the function definition.
The default arguments are given in the function prototype and should be repeated in the function definition.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
5 comments Page 1 of 1.

MATEWOS GINBARU said:   2 years ago
In C++, when default arguments are specified in the function prototype, they do not need to be repeated in the function definition.

The default values specified in the prototype are automatically considered when the function is called, and they do not need to be redeclared in the function definition.

Therefore, the correct statement is The default arguments are given in the function prototype and do not need to be repeated in the function definition.

Andres SM said:   8 years ago
B is correct. The default arguments are given in the function prototype. You can not set default values in the definition of a function.

Aman said:   1 decade ago
Prototype is used to tell the compiler that there is a function named this so if we call the function before function definition it is error so prototype is used to build function call not definition.

Pankaj said:   1 decade ago
Compiler uses the prototype information to build a call, not the function definition.

Please elaborate.

Manish said:   1 decade ago
When a function prototype have default argument, then in function definition we do not need to again repeat it. Just look at the below programme.

#include<iostream.h>
void print(int ,int a=10); // function pro type
int main()
{ int b=11;
print(b);
return 0;
}
void print(int b ,int a) //void print(int b,int a=10) is wrong
{ cout<<"a ="<<a<<endl;
cout<<"b="<<b<<endl;
}

Post your comments here:

Your comments will be displayed after verification.