Question
Consider the following function definition and variable declarations: void square(int &n){n= n*n;} int arr[] = {1,...
Consider the following function definition and variable declarations:
void square(int &n){n= n*n;}
int arr[] = {1, 2, 3};
int number = 4;
Which of the following function calls are acceptable? (can have multiple answer)
a.square(1);
b.square(2);
c.square(arr[number]);
d.square(number);
What is the output of the following code segment?
int arr[] = {1, 4, 1, 0};
for (int i=0; i < 4; ++i)
cout<<arr[i]*2;
a.1014
b.1 4 1 0 (space in between each number)
c.1410
d.0140
e.None of the above
Given array declaration int a[] = {1, 2, 3};, the value of a[3] is
a.1
b.2
c.3
d.Undefined (or out-of-bound error)
e.None of the above
Answers
Question 1:
Answer :
c.square(arr[number]);
d.square(number);
Explanation :
- Here square(arr[number]); is acceptable but square(arr[4]) will be 0
- square(number); will be 16 because square(4) will be 16
*********************************
Question 2:
Answer :e.None of the above
Explanation :
- Here each element from the array will be multiplied by 2
- hence the output will be 2820
************************************
Question 3:
Answer :e.None of the above
Explanation :Here a[3] will be 0 because array is defined with three elements and a[3] will be 0.
************************************