1. The while looping structure can be used in a C program __________.
A) when the number of repetitions is known in advance.
B) as a pre-test counting controlled loop.
C) as a pre-test conditional controlled loop.
D) all of the above
2. An infinite loop in a C program can be created in a for looping structure if __________.
A) no statements exist within the loop.
B) the condition is false before the loop is executed.
C) the control variable is incorrectly modified within the loop.
D) none of the above
3. How many times will the following loop execute?
initialize ageCounter to 0
while ageCounter is less than or equal to 4
input inputData
set testValue to equal to inputData times 1.44
increment ageCounter by 1
end while
A) 4
B) 5
C) 6
D) the loop will execute indefinitely
4. Which of the following is a true statement?
A) When coding a looping structure it is conventional to indent the statements within the body of the loop.
B) Counter controlled loops (for loops) cannot be nested.
C) Infinite loops are never used in the event-driven programming paradigm.
D) Looping is NOT one of the fundamental programming constructs.
5. The C programming language provides support for __________ and __________ looping structures only.
A) for, while
B) for, do-while
C) Pre-Test, Post-Test
6. The following C coded for statement is an example of __________.
for(;;) {
printf("Hello class!\n");
}
A) a syntax error
B) an infinite loop
C) nothing; theres no such construct in C
D) None of the above
7. In C the for and while loops are examples of pre-test looping structures.
T) True
F) False
8. Identify the counter variable in the following loop:
input currentBalance
set interest to 0
set year to 1
read maxYearsAccumulation from Database
while year is less than maxYearsAccumulation
increment year by 1
set interest to interest + 0.02 * currentBalance
set currentBalance to currentBalance * 1.02
display currentBalance
end while
A) year
B) yearsAccumulation
C) interest
D) currentBalance
9. What kind of looping structure is more appropriate in order to implement repetition in the following requirement?
Currency Conversion Program III should allow the user to enter a main menu option, which is error checked as a valid entry, and then proceed with the functionality provided by Currency Conversion Program II. If on the other hand the users choice is invalid, the program should allow the user to reenter a new main menu option which is checked again for validity.
A) if-then-else
B) switch/case
C) for
D) while or do/while
10. Which pairs of statements are equivalent?
A) j++; and j += 1;
B) ++j; and j = j + 1;
C) j += 1; with j = j + 1;
D) All of the above
11. Which of the following is NOT a true statement?
A) An array is an arrangement of related values as a block in memory.
B) An array can store values of different data type.
C) Arrays can have more than one dimension.
D) Arrays in C are zero-based.
12. The number of elements in a single-dimensional array is called the __________ of the array.
A) width
B) height
C) size
D) depth
13. All the individual elements of an array have the same __________.
A) name
B) subscript (index)
C) memory location
D) value
14. The second element of a zero-based single-dimensional array named price can be referenced by:
A) price[0]
B) price[2]
C) price2
D) price[1]
15. What will be the value stored in the third element of myArray once the following C fragment is executed?
myArray[0] = 2;
for(i = 1; i < 4; i++) {
myArray[i] = myArray[i-1] + 1;
}
A) 3
B) 4
C) 5
D) 6
16. If we assume the C declaration int myArray[4], the statement myArray[4]=2; __________.
A) will initialize the last array element to 2.
B) will be flagged as a syntax error.
C) will produce a bug (semantic error).
D) will have no effect.
17. Character strings in C must be handled as single-dimensional arrays of char data type.
T) True
F) False
18. Which of the following statements is true?
A) Arrays in C are zero-based.
B) Only for loops can be used in order to iterate over all the elements of an array.
C) An array can store values of different data type.
D) All of above
19. Assuming no user defined definitions, which of the following is a valid C declaration for a 10-character string variable named title?
A) char title[11];
B) string title [10];
C) char title [10];
D) char10 title;
20. In a C double-dimensional array named ChessBoard the statement ChessBoard[5][9] refers to:
A) The 9-th element of the 5-th row.
B) The 10-th element of the 6-th row.
C) The 5-th element of the 9-th row.
D) The 6-th element of the 10-th row.