☑ MCQ PRACTICE

Programming for Problem Solving Unit 2

Practice objective questions for quick revision and examination preparation. Try answering each question before revealing the answer.

📚 Programming for Problem Solving
📖 Unit 2
🎯 MCQs

Programming for Problem Solving - Unit-2

1
What is an array in C?
AA data structure that can hold multiple data types.
BA collection of elements with the same data type.
CA mathematical function.
DA loop construct.
Correct AnswerA collection of elements with the same data type.
2
How do you declare a one-dimensional array of integers in C?
Aint[] myArray;
Barray<int> myArray;
Cint myArray[];
Darray myArray;
Correct Answerint myArray[];
3
How do you access the third element of a one-dimensional array myArray in C?
AmyArray[2]
BmyArray[3]
CmyArray[1]
DmyArray(3)
Correct AnswermyArray[2]
4
In a two-dimensional array, how would you access the element in the second row and third column?
Aarray[2][3]
Barray[1][2]
Carray(2,3)
Darray[3][2]
Correct Answerarray[1][2]
5
What will be the output of the following code? int arr[3] = {10, 20, 30}; printf("%d", arr[1]);
A10
B20
C30
DNone of the above
Correct Answer20
6
What will the following code print? int arr[3][2] = {{1, 2}, {3, 4}, {5, 6}}; printf("%d", arr[1][1]);
A2
B3
C4
D5
Correct Answer4
7
what is the size of an integer array declared as int arr[5] in bytes?
A14
B20
C4
D5
Correct Answer20
8
Which of the following correctly calculates the total number of elements in a one-dimensional array arr declared as int arr[5];?
Asizeof(arr) / sizeof(arr[0])
Bsizeof(arr)
Carr.size()
DNone of the above
Correct Answersizeof(arr) / sizeof(arr[0])
9
What happens if you try to access an array element with an index greater than its size in C?
AIt returns a default value
BIt causes a segmentation fault
CIt wraps around to the start of the array
DNone of the above
Correct AnswerIt causes a segmentation fault
10
What is a two-dimensional array?
AAn array that can store only two elements.
BAn array of arrays, organized in rows and columns.
CAn array with two data types.
DA data structure to hold strings.
Correct AnswerAn array of arrays, organized in rows and columns.
11
Comment on an array of the void data type.
AIt can store any data-type
BIt only stores element of similar data type to first element
CIt acquires the data type with the highest precision in it
DYou cannot have an array of void data type
Correct AnswerYou cannot have an array of void data type

Fill in the Blanks

12An array is a collection of items stored at __________ in memory.
Correct Answercontiguous locations
13In C, the index of the first element in an array is __________.
Correct Answer0
14The syntax to access the fifth element of an array named arr is __________.
Correct Answerarr[4]
15To declare a two-dimensional array in C, you use two sets of __________.
Correct Answersquare brackets
16The size of a one-dimensional array must be defined during __________.
Correct Answerdeclaration
17To find the number of elements in an array arr, the expression is __________.
Correct Answersizeof(arr) / sizeof(arr[0])
18In C, if you attempt to access an index that is out of bounds, it can lead to __________.
Correct Answerundefined behavior
19The process of iterating through an array to access or modify each element is called __________.
Correct Answerlooping (or iteration)
20To access the first element of a two-dimensional array arr, you use the syntax __________.
Correct Answerarr[0][0]
← Back to All MCQs