☑ MCQ PRACTICE

Programming for Problem Solving Unit 3

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

📚 Programming for Problem Solving
📖 Unit 3
🎯 MCQs

Programming for Problem Solving - Unit-3

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
Which loop is commonly used to access array elements sequentially?
Afor
Bswitch
Cif
Dgoto
Correct Answerfor
5
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]
6
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
7
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
8
what is the size of an integer array declared as int arr[5] in bytes?
A14
B20
C4
D5
Correct Answer20
9
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])
10
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
11
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.
12
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

26An array is a collection of elements of the __________ data type.
Correct Answersame
27The first index of an array in C is __________.
Correct Answer0
28The last valid index of an array of size 10 is __________.
Correct Answer9
29The declaration int a[5]; creates an array with __________ elements.
Correct Answer5
30An array with rows and columns is called a __________-dimensional array.
Correct Answertwo
31The header file used for string functions is __________.
Correct Answerstring.h
32A string in C is terminated by: __________.
Correct Answer'\0'
33The function used to find the length of a string is __________.
Correct Answerstrlen()
34The function used to copy a string is __________.
Correct Answerstrcpy()
35The function used to concatenate two strings is __________.
Correct Answerstrcat()
36The function used to compare two strings is __________.
Correct Answerstrcmp()
37The function commonly used to read a line of text safely into a character array is __________.
Correct Answerfgets()
38The keyword used to define an enumerated type is __________.
Correct Answerenum
39An array passed to a function is generally treated as a __________ to its first element.
Correct Answerpointer
40Arrays that store related information at corresponding indexes are called __________ arrays.
Correct Answerparallel
41To access the first element of a two-dimensional array arr, you use the syntax __________.
Correct Answerarr[0][0]
← Back to All MCQs