Question: Q6 3) What is the error in the following code snippet? const int WORDCOUNT = 100; string words[WORDCOUNT]; for (int i = 0; i

Q6

3)

What is the error in the following code snippet?

const int WORDCOUNT = 100;
string words[WORDCOUNT];
for (int i = 0; i <= WORDCOUNT; i++)
{
  cout << words[i] << endl;
}

Cannot define an array of strings

Infinite loop

Array index out of bounds

Skips elements in the array

4)

Why is it unnecessary to explicitly use the & symbol whenpassing a one-dimensional array as a reference parameter?

It is not allowable to pass arrays by reference in C++

Only the elements of an array can be passed by reference

Only two-dimensional arrays can be passed by reference

One dimensional arrays are always passed by reference in C++

7)

  1. Consider the following code snippet:

    int arr[3][3] = {  { 1, 2, 3 },  { 4, 5, 6 }};
    int val = arr[0][2] + arr[2][0];
    cout << val;

    What is the output of the given code snippet on execution?

    3

    4

    5

    6

8)

The algorithm below is called:

bool found = false;
int low = 0, pos =0, high = size - 1;
while (low <= high && !found)
{
   pos = (low + high) / 2;  // Midpoint of the subsequence
   if (values[pos] == searched_value) { found = true; }
   else if (values[pos] < searched_value)
   { low = pos + 1; } // Look in second half
   else
   { high = pos - 1; } // Look in first half
}

Selection sort

Linear search

Binary sort

Binary search

9)

Which one of the following is a correct declaration for afunction named passvect with the vector num of size 5 as areference parameter?

void passvect(vector& num(5))

void passvect(vector num)

void passvect(vector& num)

void passvect(num)

10)

What is the result of the following definition of a vector?

vector points;

The statement causes a compile-time error as the size of thevector is not defined.

The statement creates a vector of size 0.

The statement creates a vector with unlimited size.

The statement creates a vector of size 1.

11)

The selection sort uses two primary operations to put theelements of an array in order:

find the minimum; and insert

find the minimum; and swap

divide and conquer; and swap

insert; and copy

13)

What should be ensured for calculating the smallest value in avector?

The vector contains at least one element.

The vector contains at least two elements.

The vector contains the maximum value in the first element.

The vector contains the least value in the first element.

14)

  1. What is the value of the variable sum after thefollowing code snippet is run?

    vector series(10);
    int sum = 0;
    for (int cnt = 0; cnt < series.size(); cnt++)
    {
     series[cnt] = cnt + 1;
     sum = sum + series[cnt];
    }

    50

    55

    0

    1

15)

  1. What should be ensured for calculating the largest value in avector?

    The vector contains at least one element.

    The vector contains at least two elements.

    The vector contains the minimum value in the first element.

    The vector contains the maximum value in the first element.

17)

What is the result of the following definition of a vector?

vector chkdata;

The statement causes a compile time error as the size of thevector is not defined.

The statement creates a vector of size 0.

The statement creates a vector with unlimited size.

The statement creates a vector of size 1.

18)

What does "adapting array algorithms" mean in the context ofproblem solving?

Converting scalar algorithms to handle arrays

Changing and/or combining common algorithms like searching,swapping, and sorting

Adjusting array index values to meet the requirements of theproblem

None of these

20)

Consider the following line of code:

int somearray[50];

Which one of the following options is a valid line of code fordisplaying the twenty-eighth element of somearray?

cout << somearray[28];

cout << somearray(28);

cout << somearray(27);

cout << somearray[27];

Step by Step Solution

3.41 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The detailed answer for the above question is provided below Question 6 3 c Array index out of bounds In this code snippet the for loop iterates from 0 to WORDCOUNT which means that it will try to acc... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!