Question
1.) Consider the following code snippet: int cnt = 0; int myarray[4][5]; for (int i = 0; i < 5; i++) { for (int j
1.) Consider the following code snippet:
int cnt = 0;
int myarray[4][5];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 4; j++)
{
myarray[j][i] = cnt;
cnt++;
}
}
What is the value of myarray[1][2] after the code snippet is executed?
Select one:
a. 9
b. 11
c. 8
d. 19
2.) Consider the following code snippet:
int numarray[2][3] = { { 3, 2, 3 }};
cout << numarray[0][0];
cout << numarray[1][0];
What is the output of the given code snippet?
Select one:
a. 31
b. 00
c. 03
d. 30
3.)
Which is true when a 2D array is used as a function parameter?
Select one:
a. Only the column size must be a constant provided as an argument to the function
b. Neither the row nor the column size are necessary
c. Only the row size must be a constant provided as an argument to the function
d. Both the row and column size must be constants provided as arguments to the function
4.)
Consider the following code snippet:
int num[3];
for (int cnt = 1; cnt < 3; cnt++)
{
num[cnt] = cnt + 1;
cout << num[cnt];
}
What is the output of the given code snippet?
Select one:
a. 11
b. 13
c. 12
d. 23
5.)
Consider the following line of code:
int somearray[50];
Which one of the following options is a valid line of code for displaying the twenty-eighth element of somearray?
Select one:
a. cout << somearray[27];
b. cout << somearray[28];
c. cout << somearray(28);
d. cout << somearray(27);
6.)
Consider the following code snippet:
void check(int chknum1[], int size)
{
int cnt = 0;
for (int i = 0; i < size; i++)
{
if (chknum1[i] == 0)
{
cnt++;
}
}
cout << "The total 0 values in the array are: " << cnt;
}
Which one of the following is true about the check function in the given code snippet?
Select one:
a. The check function removes all the elements with value 0 from an array passed as a parameter to the function.
b. The check function adds 0 to the elements of an array as a parameter to a function and also returns the array.
c. The check function counts all the elements with value 0 in an array passed as a parameter to a function and also returns the count.
d. The check function counts all the elements with value 0 in an array as a parameter to the function.
7.)
How many elements can be stored in an array of dimension 5 by 6?
Select one:
a. 5
b. 11
c. 6
d. 30
8.)
What is the output of the following code snippet?
int check(int mydata[], int size)
{
int sum = 0;
for (int i = 0; i < size; i++)
{
sum = sum + mydata[i];
}
return sum;
}
int main()
{
int vdata[3];
int rsum;
for (int cnt = 0; cnt < 3; cnt++)
{
vdata[cnt] = cnt + 1;
}
rsum = check(vdata, 3);
cout << rsum;
return 0;
}
Select one:
a. 4
b. 2
c. 6
d. 0
9.)
Which one of the following is the correct code snippet for calculating the largest value in an integer array of size 100?
Select one:
a.
int maximum = 0;
for (int counter = 1; counter < 100; counter++)
{
if (intarray[counter] > maximum)
{ maximum = intarray[counter]; }
}
b.
int maximum = intarray[0];
for (int counter = 1; counter > 100; counter++)
{
if (intarray[counter] >= maximum)
{ maximum = intarray[counter]; }
}
c.
int maximum = intarray[1];
for (int counter = 1; counter < 100; counter++)
{
if (intarray[counter] > maximum)
{ maximum = intarray[counter]; }
}
d.
int maximum = intarray[0];
for (int counter = 1; counter < 100; counter++)
{ if (intarray[counter] > maximum)
{ maximum = intarray[counter]; }
}
10.)
Which of the function prototypes below is correct for a function which processes a 2D array?
Select one:
a. int max2d(int a[][5], int rows, int columns);
b. int max2d(int a[][], int rows, int columns);
c. int max2d(int a[5][], int rows;
d. int max2d(int a[][], int rows);
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