Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Tests  >  Test: Arrays - 2 - Computer Science Engineering (CSE) MCQ

Test: Arrays - 2 - Computer Science Engineering (CSE) MCQ


Test Description

10 Questions MCQ Test - Test: Arrays - 2

Test: Arrays - 2 for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Test: Arrays - 2 questions and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus.The Test: Arrays - 2 MCQs are made for Computer Science Engineering (CSE) 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 Computer Science Engineering (CSE) & Test: Arrays - 2 solutions in Hindi for Computer Science Engineering (CSE) course. Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free. Attempt Test: Arrays - 2 | 10 questions in 30 minutes | Mock test for Computer Science Engineering (CSE) preparation | Free important questions MCQ to study for Computer Science Engineering (CSE) Exam | Download free PDF with solutions
*Answer can only contain numeric values
Test: Arrays - 2 - Question 1

What is the output for the given program?
int sum(int arr[], int n)
{
int sum = 0; 
for (int i = 0; i < n; i++)
sum += arr[i];
return sum;
}
main()
{
int arr[] = {12, 30, 40, 15};
int n = sizeof(arr) / sizeof(arr[0]);
cout << sum(arr, n);
return 0;
}


Detailed Solution for Test: Arrays - 2 - Question 1

The program is described as:
In the given code, Consider the address of the array as 100.
The main function has an array arrr[] = {12, 30, 40, 15};
int n = sizeof(arr) / sizeof(arr[0]);
sizeof(arr) = 16(4 x 2) i.e four elements and each size is 2. 
sizeof(arr[0]) = Size of element arr[0] i.e first element size = 2.
So n becomes n = 16/2
∴ n = 4
And sum(arr, n)
Here arr is the address of the array. 
sum(100, 5)
The sum function calculates the summation of elements
Initially, the sum=0 sums each element and stores it in the sum variable.
sum = 12+30+40+15
sum = 97 and returns the sum variable to the main function i.e 97.
Hence the correct answer is 97.

Test: Arrays - 2 - Question 2

Find the output of the following program
int main()
{
int i; int arr[6]={1}; 
for(i=0;i<6;i++)
{
printf("%d",arr[i]);
}
return 0;
}

Detailed Solution for Test: Arrays - 2 - Question 2

Array of size 6 is declared and is initialized by 1.
arr[0] will contain 1 and rest are by default initialized as zero.
for loop will print all that values starting from arr[0] to arr[5].
arr[0]=1
arr[1]=0
arr[2]=0
arr[3]=0
arr[4]=0
arr[5]=0
Final output print by the program is 1 0 0 0 0 0.

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

A two-dimensional array named Arr is with the range Arr[10........20, 25......45]. The base address of the array is 10 and the size of each element is 2 bytes. What will be the location of Arr[15][30] using column major order?

Detailed Solution for Test: Arrays - 2 - Question 3

CONCEPT:
If the questions ask for Row major Order, then use the formula will be Address of A[I][J] = B + W * ((I – LR) * N + (J – LC))  where N will be the number of columns.

Column major order concept: 

  • Column major order means the element in a column is stored adjacent to each other. This basically works in a 2d and 3d array.
  • Now we are given the base address along with the size of each element and the construction of a 2d array(row and column number )
  • First, we have to calculate the no. of rows here = (Row upper limit - Row lower limit) + 1 = (20 - 10) + 1 = 11.
  • We need no. of the column if the ques will ask about Row major order.
  • There is a formula available to calculate it directly(Rather than going into deep how the formula came, it's better to remember the formula.)

FORMULA:-
Address of A[I][J] is can be calculated with the formula is A[I][J] = B + ((J – LC) * M + (I – LR))*W.
where;

  • I- Row subset of an element whose address is to be found ( 15 here)
  • J = Column Subset of an element whose address is to be found,(30 here)
  • B- Base address(10 here)
  • W- storage size of one element  (2 bytes here)
  • LR- the lower limit of row (u can take start index of the matrix)- (10 in this ques)
  • LC-Lower limit of column(start column index of the matrix) - (25 in this ques)
  • M- number of rows given in the matrix. (11 here)

 Now solve the equation by solving the inner bracket first.
10+[5*11+5] *2  = 10+(60)*2 = 10+120 = 130 will be the answer.

Test: Arrays - 2 - Question 4

If integer requires two bytes space, then what will be the size of the following 'C’ array?
int array[3][4]=(0);

Detailed Solution for Test: Arrays - 2 - Question 4

An array is defined as the collection of similar types of data items stored at contiguous memory locations. 
int array[3][4] = (0);
Here Array is an integer array. which is in a two-dimensional array of 3 rows and 4 columns. So each row has 4 elements and there are three rows.
Hence total number of elements = 3 x 4 =12
Each element of size = 2 bytes.
So size of array is = 12 x 2 bytes = 24 bytes.
Hence the correct answer is 24 bytes.

Test: Arrays - 2 - Question 5

Consider the following ANSI C program.
#include
int main()
{
int arr[4][5];
int i, j;
for(i =0; i<4; i++)
{
for (j =0; j<5; j++)
{
arr [i][j] = 10 * i + j;
}
}
print("%d", *(arr[1] + 9));
return 0;
}
What is the output of the above program?

Detailed Solution for Test: Arrays - 2 - Question 5

code:
#include
int main(){
int arr[4][5];
int i, j;
for(i =0; i<4; i++){
for (j =0; j<5; j++){
arr [i][j] = 10 +i + j;
}
}
print("%d", *(arr[1] + 9));
return 0;
}

Test: Arrays - 2 - Question 6

Consider the following C program segment.
#include
int main()
{
char s1[7] = "1234", *p;
p = s1 + 2; *p = ‘0’;
printf("%s", s1);
}
What will be printed by the program?

Detailed Solution for Test: Arrays - 2 - Question 6


Where \0 is a null character 
After *p = '0';   \\s1[2] = '0'
100  101 102 103  104

printf(“%s”, s1) will print all starting from address location 100 until the null character.
Output: 1204 

Test: Arrays - 2 - Question 7

Consider the following program of ‘C’
main ( )
{
static int a [ ] = { 1, 2, 3, 4, 5, 6, 7, 8 } ;
int i;
for(i = 2; I < 6; ++i)
a [a [i] ] = a [i];
for (I = 0; I < 8 ; ++i)
printf (“%d”, a[i]);
}
The output of the program is :

Detailed Solution for Test: Arrays - 2 - Question 7

Array a

for(I = 2; I < 6; ++i)            // initially i = 2 and 2< 6(true)
a [a [i] ] = a [i];         
Iteration 1:
i = 2;
a[a[2]] = a[2]
a[3] = [3]

Iteration 2:
When i = 3, 3 < 6 (true)
a[a[3]] = a[3]
a[3] = 3      // as in iteration 1, a[3] becomes was 3

Iteration 3:
When i = 4
a[a[4]] = a[4]
a[5] = 5

Iteration 4:
When i = 5, 5 < 6 (true)
a[a[5]] = a[5]
a[5] = 5      // as in iteration 3 a[5] becomes 5.
In next iteration i becomes and condition 6 < 6 false here.
Content of array A are as follows:

Finally, it prints: 1 2 3 3 5 5 7 8

Test: Arrays - 2 - Question 8

An array name is a

Detailed Solution for Test: Arrays - 2 - Question 8

Concept:
An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together.
When an array is used as a value and array name represents the address of the first element. When an array is not used as a value its name represents the whole array.
Array name is a type of name or a type of any element name that is share by all elements of an array but its indexes are different. Array name handle as a constant pointer, it can never change during execution of a program. Array name is also used to reach its all element.
Therefore Option 3 is correct

Test: Arrays - 2 - Question 9

LB are UB are lower bound and upper bound of a linear array LA. Consider following algorithm -

  1. Repeat for K = LB to UB apply PROCESS to LA [K]
  2. Exit

The algorithm ______ the array LA.

Detailed Solution for Test: Arrays - 2 - Question 9

LB refers to the lower bound of an array ( first index element of an array ) and UB refers to the upper bound of an array, that is the last index of an array. 
Let's take an example to understand this - 
Array - [2,6,7,0,15], where 2 is the lower bound and 15 is the upper bound element.
The K is the variable that holds the index of the array. While the LA is the name of the array. A loop is used to visit to traverse the elements from LB to UB.
The K holds the index of element 2 which is 0 and reaches index 4 of element 15.
The LA array using K traverse all the elements in the array. So, Option 2 will be the answer. 

Test: Arrays - 2 - Question 10

In C, how do you properly initialise an array?

Detailed Solution for Test: Arrays - 2 - Question 10

Concept:
Array:

An array is a group of data components that are stored in the same memory region at the same time. It is the most basic data structure, in which each data piece may be retrieved simply by its index number alone.

Array initialize:
Only square brackets [ ] must be used for declaring an array. The given {}, () are not useful for array initialization.
int arr[5]={11,12,15,16,19} is correct.
The above statement can store the 5 elements in a continuous manner. consider the array base address is 100.

Hence the correct answer is  int arr[5]={11,12,15,16,19}.

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

Top Courses for Computer Science Engineering (CSE)

Download as PDF

Top Courses for Computer Science Engineering (CSE)