0% found this document useful (0 votes)
8 views

Assignment 18 Twodarray Ans

The document contains 20 multiple choice questions about arrays in C language. It covers topics like initialization of arrays, accessing array elements, 2D arrays, sorting arrays, and memory allocation for arrays. The questions test understanding of basic and some advanced concepts related to arrays in C.

Uploaded by

Yash rai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Assignment 18 Twodarray Ans

The document contains 20 multiple choice questions about arrays in C language. It covers topics like initialization of arrays, accessing array elements, 2D arrays, sorting arrays, and memory allocation for arrays. The questions test understanding of basic and some advanced concepts related to arrays in C.

Uploaded by

Yash rai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Assignment of objective questions

1. Is "holes" are allowed in Array during initialization of the array

a. Yes
b. Yes, in Turbo Compiler only.
c. Yes, in Modern Compiler only.
d. No, it will be an Error

Answer - d. No, it will be an Error

2. Predict the output


int arr[5] = {10, 20, 30, 40, 50,60};

a. Yes, we can access all the 6 indexes


b. Yes, but we can access only the first 5 indexes
c. Yes, but we can access only the last 5 indexes
d. No, it will be an Error

Answer - d. No, it will be an Error

3. Predict the output


int arr[5] = {1, 2, 3, 4, 5}, i;
for(i = 0; i <= 5; i++)
printf("%d : %d\n", i, arr[i]);

a. Print all the array elements


b. Not even compile Syntax Error
c. Not Run completely Run Time Error
d. Unpredictable Behavior

Answer - d. Unpredictable Behavior


4. How many-dimensional array we have in C language in Turbo Compiler?

a. 2-Dimensional array only


b. up to 4-Dimensional Array only
c. up to 8-Dimensional Array only
d. up to 16-Dimensional Array only

Answer - d. up to 16-Dimensional Array only

5. Which of the following is the correct syntax of declaration of the 2-dimensional


array?

a. <data_type> <array_name> [<row_size>][<column_size>];


b. <data_type> <array_name> [<row_size>][<column_size>]
c. <data_type> <array_name> <row_size> , <column_size>;
d. <data_type> <array_name> <row_size>; <column_size>;

Answer - a. <data_type> <array_name> [<row_size>][<column_size>];

6. The 2-Dimensional array also allocates space in RAM in continuous form?

a. Yes
b. No
c. In Matrix Form
d. In Linked List Form

Answer - a. Yes
7. Predict the output
int arr[3][4];
arr[0] = 25;

a. Yes, Run but with unpredictable output


b. Yes, Run with Runtime Error
c. No, Run Time Error
d. No, Syntax Error

Answer - d. No, Syntax Error

8. Which of the following is the correct syntax of accessing 2-Dimensional Array

a. <array_name> [<row_index>][<column_index>] = <value>;


b. <array_name> <row_index>, <column_index> = <value>;
c. <array_name> <row_index>; <column_index> = <value>;
d. <array_name> <row_index> . <column_index> = <value>;

Answer - a. <array_name> [<row_index>][<column_index>] = <value>;

9. What is the output of the following code?


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

a. 3 4 5
b. 2 4 4
c. 2 3 4
d. 2 4 5
Answer - b. 2 4 4
10. What is the output of the following program?
#include <stdio.h>
main()
{
int a[] = {1, 2, 3};
printf("% %d", a[0], 1[a]);
}

a. 1 2
b. 1 1
c. Error
d. 2 1

Answer - a. 1 2

11. Find the output of the following program


#include <stdio.h>
main()
{
int k, x, y, a[] = {21, 2, 13};
for(x = 0; x < 2; x++)
for(y = x + 1; y < 3; y++)
if(a[x] > a[y])
{
k = a[x];
a[x] = a[y];
a[y] = k;
}
printf("%d %d %d", a[0], a[1], a[2]);
}

a. 21 2 13
b. 2 21 13
c. 13 2 21
d. 2 13 21

Answer - d. 2 13 21
12. Find the output of the following program
#include <stdio.h>
main()
{
int x, y = 0, a[] = {11, 34, 21, 2, 13};
for(x = 0; x < 5; x++)
if(y < a[x])
y = a[x];
printf("%d", y);
}

a. 34
b. 43
c. 2
d. 21

Answer - a. 34

13. What will happen if in a C program you assign a value to an array element
whose subscript exceeds the size of the array?

a. The element will be set to 0


b. The compiler would report an error
c. The array size would appropriately grow
d. The program may crash if some important data gets overwritten.

Answer - d. The program may crash if some important data gets overwritten.
14. Find the output of the following program
#include <stdio.h>
main()
{
int x[4];
printf("%d %", sizeof(x), sizeof(x[0]));
}

a. 8 2
b. 2 2
c. 8 8
d. Error

Answer - a. 8 2

15. Which is the correct declaration of a two-dimension array

a. int a[3][] = {2, 3, 4, 6, 7, 8, 9};


b. int a[][] = {2, 3, 4, 6, 7, 8, 9};
c. int a[][4] = {2, 3, 4, 6, 7, 8, 9};
d. All are correct

Answer - c. int a[][4] = {2, 3, 4, 6, 7, 8, 9};

16. Consider the following declaration


int a[3][4][5] = {22, 34, 5, 6, 1, 0, 55, 4};
Which of the following statement is incorrect?

a. Total memory occupied by the array is 120 bytes


b. There are 3 two dimensional arrays, each is an array of 4 arrays of 5 int
blocks.
c. Value of a[0][1][2] is 0
d. Value of a[0][1][1] is 55

Answer - a. Total memory occupied by the array is 120 bytes


17. Find the output of the following program
#include <stdio.h>
int main()
{
int arr[5];/*Assume that base address of arr is 2000 and size of integer is 32
bit*/
arr++;
printf("%u", arr);
return 0;
}

a. 2002
b. 2004
c. 2020
d. Lvalue required

Answer - d. Lvalue required

18. Find the output of the following program


int main()
{
int i;
int arr[5] = {1};
for(i = 0; i < 5; i++)
printf("%d ", arr[i]);
return 0;
}

a. 1 followed by four garbage value


b. 1 0 0 0 0
c. 1 1 1 1 1
d. 0 0 0 0 0

Answer - b. 1 0 0 0 0
19. Is the following declaration of two-dimension array is correct?
int b[][3] = {12, 65, 78, 45, 33, 21};

a. Yes
b. No, Syntax Error
c. NO, Runtime Error
d. Compile, but the unpredictable output

Answer - a. Yes

20. Is the following declaration of two-dimension array is correct?


int b[2][] = {12, 65, 78, 45, 33, 21};

a. Yes
b. No, Error
c. NO, Runtime Error
d. Compile, but the unpredictable output

Answer - b. No, Error

You might also like