C++ Programming - Functions - Discussion

Discussion Forum : Functions - General Questions (Q.No. 5)
5.
Which of the following statement will be correct if the function has three arguments passed to it?
The trailing argument will be the default argument.
The first argument will be the default argument.
The middle argument will be the default argument.
All the argument will be the default argument.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
29 comments Page 1 of 3.

RajiSaj said:   10 years ago
Only the argument at the end of the argument list can have default arguments.

Because if you insert the default arguments at the middle of the argument list, the compiler would lose track of what arguments went where.

void badfunc(int, int=2,int) // Wrong way...

void okfunc(int, int=2, int=5); // Correct.

Trust said:   9 years ago
Please help me with this question.

Write a program that declares 3 arrays of size 4 by 3 type integer your program should read the value of the two arrays, add the two array values and store the results in the third array declare another function to add two arrays and store the result in the third one.

Naresh punia said:   1 decade ago
If you have not defined default argument in function definition then there will be no default argument. By the way default argument always come in RHS of argument list.

Jhuma biswas said:   7 years ago
By seeing different arguments I become confused which one is right answer. I can't learn anything. It became too much confusing as well as I am losing the reliability.

Mayank Panchal said:   10 years ago
When you go left to right the rightest part is called trail. Trailing arguments means you should keep default arguments in the rightest position.

Nitish said:   9 years ago
Trailing argument means. In function right side argument is trailing argument.

e.g int fun (int, int, int a=4) ; int a=4 is trailing argument.

G AKHIL said:   9 years ago
One important point to note is that only the trailing arguments can have default value and therefore we must add defaults from right to left.

Mandy said:   7 years ago
One more important point is that [D] will be also a correct answer because all arguments of a function will be default arguments.

Sakshi said:   5 years ago
Only the trailing arguments can have default values and therefore we must add default values form right-to-left.

Anurag Kumar said:   1 decade ago
If a function has three arguments then it is not necessary that the trailing argument will be default argument.


Post your comments here:

Your comments will be displayed after verification.