Skip to main content

Introduction to Programming MCQs with Answers

Practice important Introduction to Programming MCQs with answers and explanations.

Chapter: 11
Q161:
What is the index of the last element in an array of size 20?
A. 19
B. 20
C. 21
D. 18
Correct Answer: A
Chapter: 11
Q162:
How do you declare an array of integers with a size of 10 in C?
A. int array[10];
B. array int[10];
C. int[10] array;
D. int array(10);
Correct Answer: A
Chapter: 11
Q163:
What does the statement int age[10] = {0}; do?
A. Initializes the first element to zero and the rest to garbage
B. Initializes all elements to zero
C. Initializes the array with random values
D. Initializes the array with ten zeroes
Correct Answer: B
Chapter: 11
Q164:
In the context of arrays, what does the term "contiguous area of memory" refer to?
A. Memory that is allocated randomly
B. Memory allocated in non-sequential blocks
C. Memory locations that are adjacent to each other
D. Memory allocated on the stack
Correct Answer: C
Chapter: 11
Q165:
Which loop construct is best suited for reading an unknown number of inputs until a sentinel value is encountered?
A. For loop
B. While loop
C. Do-while loop
D. Infinite loop
Correct Answer: C
Chapter: 11
Q166:
What is the result of rand() % 6 in C?
A. A random number between 0 and 5
B. A random number between 1 and 6
C. A random number between 0 and 6
D. A random number between 1 and 5
Correct Answer: A
Chapter: 11
Q167:
How can you copy all elements from array a to array b if both arrays have the same size?
A. Using a loop to assign each element from a to b
B. Directly assigning b = a
C. Using the memcpy function
D. Using the copy function
Correct Answer: A
Chapter: 11
Q168:
What happens if you try to access array[10] in an array of size 10?
A. Accesses the 10th element
B. Causes a runtime error
C. Accesses the 9th element
D. Initializes the 11th element
Correct Answer: B
Chapter: 11
Q169:
What is the purpose of using the const keyword in array declarations?
A. To make the array size modifiable
B. To declare a variable that cannot be changed
C. To ensure array elements are not modified
D. To make the array dynamically allocated
Correct Answer: B
Chapter: 11
Q170:
How do you initialize an array of 100 integers to zero in C?
A. int a[100] = {0};
B. int a[100] = {0, 0, ...};
C. for (int i = 0; i < 100; i++) a[i] = 0;
D. int a[100] = {0};
Correct Answer: C
Chapter: 11
Q171:
Which of the following statements about array indexing is correct?
A. The index starts from 1 and ends at size of the array
B. The index starts from 0 and ends at size of the array minus 1
C. The index starts from 1 and ends at size of the array minus 1
D. The index starts from 0 and ends at size of the array
Correct Answer: B
Chapter: 12
Q172:
Which of the following is used to store a string in C?
A. int
B. float
C. char
D. double
Correct Answer: C
Chapter: 12
Q173:
How do you declare a character array of size 100 in C?
A. char name[100];
B. int name[100];
C. float name[100];
D. double name[100];
Correct Answer: A
Chapter: 12
Q174:
What character does C use to terminate a string?
A. Space
B. Newline
C. Null character
D. Tab
Correct Answer: C
Chapter: 12
Q175:
What is the size of the array needed to store the string 'Hello World' in C?
A. 12
B. 11
C. 13
D. 10
Correct Answer: A
Chapter: 12
Q176:
How does the 'cin' statement read a string into a character array?
A. Reads character by character
B. Reads until a newline is encountered
C. Reads until a space is encountered
D. Reads fixed length
Correct Answer: B
Chapter: 12
Q177:
In the context of arrays, what does the 'null character' signify?
A. End of the string
B. Start of the string
C. Empty space
D. End of the array
Correct Answer: A
Chapter: 12
Q178:
What is the purpose of a loop that checks for the null character while displaying a string?
A. To ensure all characters are printed
B. To avoid printing garbage values
C. To count the number of characters
D. To find the length of the string
Correct Answer: B
Chapter: 12
Q179:
Which loop structure can be used to display a string in C?
A. for loop
B. while loop
C. do-while loop
D. All of the above
Correct Answer: D
Chapter: 12
Q180:
How can we compare two arrays to check if they are equal?
A. By comparing their sizes only
B. By comparing their values one by one
C. By comparing their addresses
D. By checking if they are of the same type
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Introduction to Programming

🚀 Start Quiz Now