1 Consider the following function definition: void fillArray(int a[], int arrayS
ID: 3553512 • Letter: 1
Question
1 Consider the following function definition:
void fillArray(int a[], int arraySize)
{
for (int k = 0; k < arraySize; k++)
a[k]=2*k;
}
Which of the following is an acceptable function call?
int myArray[30]={1, 2, 3}, a;
(a) fillArray (myArray, 35); (b) a = fillArray (myArray, 30);
(c) fillArray (myArray, 30); (d) fillArray (myArray[30],30);
2 What is the output of the following statements?
int linearSearch(int list[], int key, int arraySize)
{
for (int i=0; i<arraySize; i++)
{
if (key == list[i])
return i+1;
}
return -1;
}
Explanation / Answer
1.) The answer can not be (b) because this fill array has a void return type.
So, it will not return any value.
The answer caan't be (d) because while calling function we oly pass name of variable not its size.
The answer is not (a) because the size of my array is 30. So, only 30 elements can be entered So, loop will run only for 30 times. So, array size can be 30 only.
So, the answer is (C).
2.) When we are calling function, value of parameter key is 7. And inside function, we are searching for key in left which is not at all present in the array.
So, nothing will be returned from for loop.
And after this loop only 1 value is present which is -1. So, that value is printed or returned.
So, answer is (C).
3.) The answer can't be (C) because function is returning double value. Because function declaration in (C) has void data type,
Same reason is for (b) also.
The paramters in function call is first double and second one is int. which is in option (d).
So, (d) is correct answer.
4.) The use of constructor is only and only for creation of an object and it is called only and only when object is used.
So, answer is (d)
5.) The answer cannot be (a) or (d) because we cannot access a non static function of class w/o an object of that class. The answer can't also be (b) because 'result' is a private variable and cannot be accessed. So the answer is (c)
6.) b
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.