Poly: Intro To Program Final Review (view in order)
3.Answer: D
Division by zero
1. Answer: B
machine language code
4.Answer: D
nothing
Which of the following will generate an error?
printf("%s\n", answer == 7 ? "correct" : "incorrect"); answer == 7 ? puts("correct") : puts("incorrect"); puts(answer == 7) ? "correct" : "incorrect"); if (answer == 7) { puts("correct"); } else { puts("incorrect"); }
Answer: C
puts(answer == 7) ? "correct" : "incorrect");
6.Answer: A
1. parentheses 2. multiplication, division, and remainder 3. addition and subtraction 4. assignment
1. The C compilation process is the process of translating C Language source code into:
a) graphics code b) natural language code c) machine language code d) text code
6.The precedence for arithmetic operations is the following:
a) parentheses; multiplication, division, and remainder; addition and subtraction; assignment b) parentheses; addition and subtraction; multiplication, division, and remainder; assignment c) parentheses; multiplication and division; addition, subtraction, and remainder; assignment d) assignment, parentheses; multiplication, division, and remainder; addition and subtraction
An uninitialized variable contains ________. a) the value last stored in the memory location reserved for that variable b) no value c) a value of zero d) a randomly assigned value
a) the value last stored in the memory location reserved for that variable
In which of the following is y not equal to 5 after execution? Assume that x is equal to 4. a) y = x++; b) y = ++x; c) y = 5; d) y = x = 5;
a) y = x++;
What is the highest value assumed by the loop counter in a correct for statement with the following header? for (i = 7; i <= 72; i += 7) a) 7 b) 77 c) 70 d) 72
b) 77
A programmer writes a for statement to count from 1 to 10 and explicitly mentions the 1 and the 10 in the for "header." Which relational operator would probably be used in the loop-continuation test? a) >= b) <= c) < d) >
b) <=
In a switch statement: a) a default case is required b) multiple actions do not need to be enclosed in braces c) a break is required after each case d) a break is required after the default case
b) multiple actions do not need to be enclosed in braces
The program segment int counter = 1; do { printf("%i ", counter); } while (++counter <= 10); will ________. a) print the numbers 1 through 11 b) print the numbers 1 through 10 c) cause a syntax error d) print the numbers 1 through 9
b) print the numbers 1 through 10
What is produced by a for statement with a correct body and with the following header for (i = 20; i >= 2; i += 2) a) the even values of i from 20 down to 2 b) a syntax error c) an infinite loop d) a divide-by-zero error
c) an infinite loop
Which of the following is an incorrect expression to increment c by 1 in the increment expression of a for "header?" a) c += 1 b) c++ c) c + 1 = c d) ++c
c) c + 1 = c
5.Answer: D
character = 'T';
Answer: C
control structure
The condition num != 65 cannot be replaced by: a) num - 65 b) num > 65 || num < 65 c) !(num == 65) d) !(num - 65)
d) !(num - 65)
Which data type should normally not be used to control a counting loop? a) long b) short c) int d) float
d) float
Using an incorrect relational operator or using an incorrect final value of a loop counter in the condition of a while or for statement is a frequent cause of __________errors. a) syntax b) divide-by-zero c) compilation d) off-by-one
d) off-by-one
Which of the following encompasses the other three?
iteration structure/repetition structure selection structure control structure sequence structure
2. Answer: C
Result = 8.
Which of the following will not increment variable c by one? a) c + 1; b) c += 1; c) ++c; d) c++;
a) c + 1;
4.If the int variable someInt contains the value 26, the statement printf("The output is"%d, someInt); outputs the value:
a) 26 b) 0 c) 26.0 d) nothing
What is the final value of x after performing the following operations? int x = 21; double y = 6; double z = 14; y = x / z; x = 5.5 * y; a) 8 b) 5 c) 8.25 d) 5.5
a) 8
2. What result should be expected for the following code? #include <stdio.h> #define DIVIDE(a,b) (a/b) int main () { printf("Result = %d. \n", DIVIDE (5 + 4, 2 + 1 )); return 0; }
a) Result = 3. b) Result = DIVIDE (5 + 4, 2 + 1 ). c) Result = 8. d) Result = (a,b).
3.Which of the following error is NOT an example of a compilation-time error?
a) Spelling b) Punctuation c) Matching of parentheses d) Division by zero
How many times will the following program print hello? i = 1; while (i <= 10) { puts("hello"); } a) an infinite number of times b) 10 c) 8 d) 0
a) an infinite number of times
Answer: A
Passed
If grade has the value of 60 what will the following code print? if (grade >= 60) { puts("Passed"); }
Passed nothing puts("Passed"); 60
Which of the following is not specified by the following code segment: for (c = 1; c <= 10; c++) a) body statement of the loop b) initial value of the loop counter c) increment of the loop counter d) loop continuation test
a) body statement of the loop
5.A character is a number that represents a letter, a number, or a symbol. Which of the following is the best syntax to assign a character T to a char variable?
a) character = "T"; b) character = \T; c) character = \\T; d) character = 'T';