Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q161: What is the index of the last element in an array of size 20?
- A: 19
- B: 20
- C: 21
- D: 18
View Answer
A
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);
View Answer
A
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
View Answer
B
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
View Answer
C
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
View Answer
C
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
View Answer
A
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
View Answer
A
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
View Answer
B
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
View Answer
B
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};
View Answer
C