Question
1)A parameter in a C++ function is passed by value. Which of following statement is true? I. The value of the real parameter is passed
1)A parameter in a C++ function is passed by value. Which of following statement is true? I. The value of the real parameter is passed to the formal parameter; II. Changing the value of the formal parameter in the function will not change the real parameter; III. Changing the value of the formal parameter in the function will change the real parameter as well.
a. I only b. II only c. I and II only.
15)Consider an integer array a of length n with indexing starting at 0, where n is a positive integer. If the elements of the array a are to be written out in reverse order, which of the following C++ code fragment does NOT do the job?
a. int i=n-1; while (i>=1){ cout << a[i] << endl; i = i-1; } cout << a[i] << endl; | |
b. int i=n-1; while (i>=1){cout << a[i] << endl; i = i-1;} | |
c. int i=n-1; while (i>=0){cout << a[i] << endl; i = i-1;} |
16)Consider the following C++ function, where variable A is an array of length n, which is a positive integer.
int test(int n, int* A){
int x=0;
for( int i=0; i
if (i%2==1){ x += A[i];}
}
return x;
}
What value does test function return?
b. The largest odd value in the array A | |
c. The number of odd values in the array A | |
d. The sum of the odd values in the array A | |
e. The sum of the values in odd-numbered index in the array A |
28)Consider the following program segment, where a is an integer constant and b is an integer variable
that holds a positive value.
int r = 0;
int n = b;
while (n != 0){ r += a; n--; }
Which of the following is a loop invariant for the while loop?
b. r= b(a-1) | |
c. r = a + b | |
d. r = ab - 1 | |
e. r = ab |
111)When a C++ function is called, where are parameters of the function allocated?
Question 11 options:
a. in the runtime calling stack after return value if its not a void function | |
b. at a fixed position | |
c. in the runtime stack after local variables | |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started