Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Engr. 50 Exam I11 Spring 2018 Name: Complete, Neat, and Detailed solutions are r

ID: 3709587 • Letter: E

Question

Engr. 50 Exam I11 Spring 2018 Name: Complete, Neat, and Detailed solutions are required for credit. Choose 5 of the first 6 problems+ do problem number 7. If you do all of the first 6 problems, you will get 10 extra credit points for the one that you selected as extra credit . Consider the following function definition: void tripler (int &n;) 1. 3*n; = n Given this definition, which of the following are acceptable function calls? Explain your answer for each (why or why not). int a[3] = {3,4,5}, number - 2; a) tripler (a[2]); b) tripler (a [3]): c) tripler (a [number]); d) tripler (); e) tripler (number);

Explanation / Answer


as we are declaring a refrance variable in the function tripler so becomes an alternative name for an existing variable
and it will behave as normal variable so :


(a) the first system call will be valid as we are passing the value at the index 2 of the array
that is 5 that will passed to the aurgument


(b) it will also work fine but will pass a garbage value to the function so the output will not be
pridicted but it is a valid call
(c) function call third (c) will also work fine and pass the value of the index 2 that will be passed to the function

(d) the fuction call d is not a valid function call because we are calling withot passing any value
and in the given function declaration it is ascepting a value .
so it will give the following error-
too few arguments to function 'int trippler(int&)


(e) this is also a valid function call because we are simply passing the value of the number to the
referance variable n that will becomes an alternative name for an existing variable

/* Feel free to ask if u have any doubt */