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
803 views
in Functions by (30.4k points)
closed by

Consider the following function definition. 

int add (int a, int b=2, int c=5) 

int s = a + b + c; 

cout<<“Sum is :”<<s;

}

Predict the output of the above code for the following function calls: 

1. add (5, 8, 10); 

2. add (5, 8); 

3. add (5);

1 Answer

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

1. add(5, 8, 10). Here a = 5, b = 8 and c = 10. 

Then It prints 23(5 + 8 + 10) 

2. add(5, 8). Here a = 5, b = 8 and no value for c then c will take the default value 5. 

Hence it prints 18(5 + 8 + 5(default value for c)). 

3. add(5). Here a = 5 and no values for b and c, then b and c will take the default values 2 and 5 respectively. 

Hence it prints 12(5 + 2 + 5(default values for b and c)).

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.

Categories

...