Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
1.0k views
in Functions by (49.1k points)
closed by

What is default arguments? Give example.

1 Answer

+1 vote
by (54.8k points)
selected by
 
Best answer

In C++, one can assign default values to the formal parameters of a function prototype. 

The Default arguments allows to omit some arguments when calling the function.

1. For any missing arguments, complier uses the values in default arguments for the called function.

2. The default value is given in the form of variable initialization.

Example : void defaultvalue(int n1 = 10, n2 = 100);

3. The default arguments facilitate the function call statement with partial or no arguments.

Example :

1. defaultvalue (x, y);

2. defaultvalue (200, 150);

3. defaultvalue (150);

4. defaultvalue (x, 150);

4. The default values can be included in the function prototype from right to left, i.e., we cannot have a default value for an argument in between the argument list.

Example:

1. void defaultvalue (int n1=10, n2);//invalid prototype.

2. void defaultvalue (int n1, n2 = 10);//valid prototype.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...