Back-End Programming Exam  >  Back-End Programming Tests  >  Test: Arrays - 2 - Back-End Programming MCQ

Test: Arrays - 2 - Back-End Programming MCQ


Test Description

15 Questions MCQ Test - Test: Arrays - 2

Test: Arrays - 2 for Back-End Programming 2024 is part of Back-End Programming preparation. The Test: Arrays - 2 questions and answers have been prepared according to the Back-End Programming exam syllabus.The Test: Arrays - 2 MCQs are made for Back-End Programming 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Arrays - 2 below.
Solutions of Test: Arrays - 2 questions in English are available as part of our course for Back-End Programming & Test: Arrays - 2 solutions in Hindi for Back-End Programming course. Download more important topics, notes, lectures and mock test series for Back-End Programming Exam by signing up for free. Attempt Test: Arrays - 2 | 15 questions in 30 minutes | Mock test for Back-End Programming preparation | Free important questions MCQ to study for Back-End Programming Exam | Download free PDF with solutions
Test: Arrays - 2 - Question 1

What is a array?

Test: Arrays - 2 - Question 2

An array elements are always stored in ________ memory locations.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Arrays - 2 - Question 3

What is the output of following program?

#include <stdio.h>
int main()
{
    int a[][] = {{1,2},{3,4}};
    int i, j;
    for (i = 0; i < 2; i++)
        for (j = 0; j < 2; j++)
            printf("%d ", a[i][j]);
    return 0;
}

Detailed Solution for Test: Arrays - 2 - Question 3

There is compilation error in the declaration " int a[][] = {{1,2},{3,4}};". Except the first dimension, every other dimension must be specified.
int arr[] = {5, 6, 7, 8} //valid
int arr[][5] = {}; //valid
int arr[][] = {}; //invalid
int arr[][10][5] = {}; //valid
int arr[][][5] = {}; //invalid

Test: Arrays - 2 - Question 4

Which of the following gives the memory address of the first element in array?

Test: Arrays - 2 - Question 5

What will be printed after execution of the following code?
void main()
{
      int arr[10] = {1,2,3,4,5};
      printf("%d", arr[5]);
}

Test: Arrays - 2 - Question 6

For a C program accessing X[i][j][k], the following intermediate code is generated by a compiler. Assume that the size of an integer is 32 bits and the size of a character is 8 bits.
t0 = i * 1024
t1 = j * 32
t2 = k * 4
t3 = t1 + t0
t4 = t3 + t2
t5 = X[t4]
Which one of the following statements about the source code for the C program is CORRECT?

Detailed Solution for Test: Arrays - 2 - Question 6

The final expression can be simplified in form ofi, j and k by following the intermediate code steps in reverse order
t5 = X[t4]
   = X[t3 + t2]
   = X[t1 + t0 + t2]
   = X[i*1024 + j*32 + k*4]
   = X + i*1024 + j*32 + k*4 
Since k is multiplied by 4, the array must be an int array. We are left with 2 choices (A and B) among the 4 given choices. X[i][j][k]'th element in one dimensional array is equivalent to X[i*M*L + j*L + k]'th element in one dimensional array (Note that multi-dimensional arrays are stored in row major order in C). So we get following equations
j*L*4 = j*32, we get L = 8 (4 is the sizeof(int))
i*1024 = i*M*L*4, we get M = 1024/32 = 32
Therefore option A is the only correct option as M and L are 32 and 8 respectively only in option A.

Test: Arrays - 2 - Question 7

What is the output of this program?

#include < stdio.h >

using namespace std;

int main()

{

char str[5] = "ABC";

cout << str[3];

cout << str;

return 0;

}

Detailed Solution for Test: Arrays - 2 - Question 7

We are just printing the values of first 3 values.

Test: Arrays - 2 - Question 8

What will be the output of the program ?

#include"stdio.h"
int main()
{
        int a[5] = {51, 1, 5, 20, 25};
        int x, y, z;
        x = ++a[1];
        y = a[1]++;
        z = a[x++];
        printf("%d, %d, %d", x, y, z);
    return 0;
}

Test: Arrays - 2 - Question 9

Find out the correct statement for the following program.

#include "stdio.h"

int * arrPtr[5];

int main()

{

 if(*(arrPtr+2) == *(arrPtr+4))

 {

   printf("Equal!");

 }

 else

 {

  printf("Not Equal");

 }

 return 0;

}

Detailed Solution for Test: Arrays - 2 - Question 9

Here arrPtr is a global array of pointers to int. It should be noted that global variables such arrPtr are initialized to ZERO. That’s why all are elements of arrPtr are initialized implicitly to ZERO i.e. correct answer is b.

Test: Arrays - 2 - Question 10

What will be the output of the program ?

#include"stdio.h"
int main()
{
    int arr[5] = {10};
    printf("%d", 0[arr]);
    
    return 0;
}

Test: Arrays - 2 - Question 11

Pick the best statement for the below program:

#include "stdio.h"
void fun(int n)
{
   int idx;
   int arr1[n] = {0};
   int arr2[n];
   for (idx=0; idx<n; idx++)
       arr2[idx] = 0;   
}

  int main()
{
   fun(4);
   return 0;
}

Detailed Solution for Test: Arrays - 2 - Question 11

There’s no issue with definition of arr1 and arr2. In definition of these arrays, the mention of array size using variable is ok as per C standard but these types of arrays can’t be initialized at the time of definition. That’s why initialization of arr1 is incorrect. But initialization of arr2 is done correctly. Right answer is C.

Test: Arrays - 2 - Question 12

What is right way to Initialize array?

Test: Arrays - 2 - Question 13

Let a be an array containing n integers in increasing order. The following algorithm determines whether there are two distinct numbers in the array whose difference is a specified number S > 0.

i = 0;
j = 1;
while (j < n )
{
    if (E) j++;
    else if (a[j] - a[i] == S) break;
    else i++;
}
if (j < n)
    printf("yes")
else
   printf ("no");
Choose the correct expression for E.

Test: Arrays - 2 - Question 14

Let x be an array. Which of the following operations are illegal?
I. ++x
II. x+1
III. x++
IV. x*2

Test: Arrays - 2 - Question 15

Consider the C program given below :

#include <stdio.h>
int main ()    {
    int sum = 0, maxsum = 0,  i,  n = 6;
    int a [] = {2, -2, -1, 3, 4, 2};
    for (i = 0; i < n; i++)    {
            if (i == 0 || a [i]  < 0  || a [i] < a [i - 1])  {
                     if (sum > maxsum) maxsum = sum;
                     sum = (a [i] > 0) ? a [i] : 0;
            }
            else sum += a [i];
    }
    if (sum > maxsum) maxsum = sum ;
    printf ("%dn", maxsum);

What is the value printed out when this program is executed?

Detailed Solution for Test: Arrays - 2 - Question 15

If you look for loop carefully, you will notice that it assigns sum variable to some value in if condition and increments it in the else condition. On further thought, it would be clear that this loop stores sum of increasing subsequence of positive integers in sum variable and max of sum in maxsum. Hence, maxsum - maximum sum of increasing subsequence of positive integers will get printed out when this program is executed, which is 3 + 4 = 7. This solution is contributed by Vineet Purswani //output will be 3+4 =7 {for || if 1st argument is true 2nd argument will not be calculated, and if 1st argument is false, 2nd argument will be calculated}

Another Solution : When i=1 -> i==0 is false, but a[i]<0 is true so condition (1) is true.Now if (sum > maxsum) is true, since sum=2 and maxsum=0.So maxsum=2. sum = (a [i] > 0) ? a [i] : 0; , sum=0 since a[i]<0.
When i=2 -> i==0 is false, a[i]<0 is true and so condition (1) is true.Now if (sum > maxsum) is false, since sum=0 and maxsum=2.Since sum = (a [i] > 0) ? a [i] : 0; , sum=0 since a[i]<0.
When i=3 -> i==0 is false , a[i]<0 is false and a [i] < a [i – 1] is false so condition (1) is false. Now sum += a [i] = 3.
When i=4 -> i==0 is false , a[i]<0 is false and a [i] < a [i – 1] is false so condition (1) is false. Now sum += a [i] = 7.
When i=5 -> i==0 is false , a[i]<0 is false and a [i] < a [i – 1] is true so condition (1) is true. sum > maxsum is true, since sum=7 and maxsum=2,so maxsum=7.Since sum = (a [i] > 0) ? a [i] : 0, so sum=2 since a[5]>0.

Information about Test: Arrays - 2 Page
In this test you can find the Exam questions for Test: Arrays - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Arrays - 2, EduRev gives you an ample number of Online tests for practice
Download as PDF