Chapter 3
If x = 3, which of the following sets xto 7? (a) x *= 4; (b) x += 4; (c) x =+ 4; (d) x + 4 = x;
(b) x += 4;
In which of the following is ynot equal to 5after execution? As-sume thatx is equal to 4. (a) y = 5; (b) y = x++; (c) y = ++x; (d) y = x = 5;
(b) y = x++;
If grade has the value of 60 what will the following code print? if (grade >= 60) { puts("Passed"); } (a) nothing (b) 60 (c) Passed (d) puts("Passed");
(c) Passed
What is wrong with the following loop?While (sum <= 1000) { sum = sum + 30; } (a) The parenthesis should be braces. (b) The braces around sum = sum +30; should be removed. (c) While should be while. (d) There should be a semicolon after While (sum <=1000).
(c) While should be while.
How many types of control statements exist in C? (a) 3 (b) 7 (c) 5 (d) 2
(a) 3
Which of the following statements is true? (a) A counter variable that stores only non-negative numbers should be declared as an unsigned integral type. (b) A counter variables that stores only non-negative numbers should be declared as a signed integral type.(c) The type of a counter does not matter (d)None of the above.
(a) A counter variable that stores only non-negative numbers should be declared as an unsigned integral type.
Which of the following will not increment variable c by one? (a) c + 1; (b) c++; (c) ++c; (d) c += 1;
(a) c + 1;
Pseudocode does not typically include __________. (a) definitions (b) input/output (c) action statements (d) control statements
(a) definitions
The conditional operator (?:) ________. (a) is the only ternary operator in C (b) is a unary operator (c) associates from left to right (d) accepts two operands
(a) is the only ternary operator in C
In indefinite iteration, an input value (a) should always be evaluated before being processed (b) should always be processed directly after it is entered (c) should never be modified (d) can be entered, processed, and evaluated in any order
(a) should always be evaluated before being processed
An uninitialized variable contains ________. (a) the value last stored in the memory location reserved for that vari-able (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 vari-able
The empty statement is represented by placing __________ where a statement would normally be. a) empty b) ; c) null d) :
b) ;
Which of the following statements is true about undefined behav-ior, which can leave a system open to attack? (a) It's not possible to have undefined behavior when adding two inte-gers. (b) Adding two integers can result in arithmetic overflow, which can cause undefined behavior. (c) You should not worry about undefined behavior in your programs. (d)None of the above.
(b) Adding two integers can result in arithmetic overflow, which can cause undefined behavior.
Indentation in the if selection statement is ________. (a) always mandatory (b) always optional (c) only mandatory if there is more than one statement following the if statement (d) only optional if there is more than one statement following the ifstatement
(b) always optional
Which of the following will generate an error? (a) if (answer == 7) { puts("correct"); } else { puts("incorrect"); } (b) puts(answer == 7 ? "correct" : "incorrect"); (c) printf("%s\n", answer == 7 ? "correct" : "incor-rect"); (d) answer == 7 ? puts("correct") : puts("incorrect");
(b) puts(answer == 7 ? "correct" : "incorrect");
Indefinite iteration is controlled by a (a) counter (b) sentinel value (c) data value (d) non-constant condition
(b) sentinel value
Which of the following is true of pseudocode programs? (a) they are executed by the computer (b) they help the programmer "think out" a program (c) they typically include definitions and all types of statements (d) all of the above are false
(b) they help the programmer "think out" a program
How many times will the following program print hello?i = 1; while (i <= 10) { puts("hello"); } (a) 10 (b) 8 (c) an infinite number of times (d) 0
(c) an infinite number of times
Which assignment expression is equivalent to c = c / 2 ?(a) c / = 2 (b) c / c = 2 (c) c /= 2 (d) c =/ 2
(c) c /= 2
Which of the following encompasses the other three?(a) sequence structure (b) iteration structure (c) control structure (d) selection structure
(c) control structure
In a flowchart of an algorithm, what is the shape of the decision sym-bol? (a) circle (b) rectangle (c) diamond (d) rounded rectangle
(c) diamond
Which of the following is an iteration statement? (a) if (b) if...else (c) do...while (d) switch
(c) do...while
Which operation does not take place in the following example? int x = 21; double y = 6; double z = 14; y = x / z; x = 5.5 * y; (a) implicit conversion (b) promotion (c) explicit conversion (d) truncation
(c) explicit conversion
A statement is called a block if it ________. (a) is a compound statement (b) contains definitions (c) is a compound statement that contains definitions (d) does not contain definitions
(c) is a compound statement that contains definitions
Having a loop within a loop is known as (a) recursion (b) doubling up (c) nesting (d) a redundancy
(c) nesting
Specifying the order in which statements are to be executed in a computer program is called (a) an algorithm (b) transfer of control (c) program control (d) pseudocode
(c) program control
What is the final value of xafter performing the following opera-tions? int x = 21; double y = 6; double z = 14; y = x / z; x = 5.5 * y; (a) 8.25 (b) 5.5 (c) 5 (d) 8
(d) 8
A fatal logic error is always caused by: (a) not initializing variables before executing an iteration statement (b) choosing a sentinel value that is also a data value (c) using a counter variable in a calculation after the loop (d) an attempt to divide by zero
(d) an attempt to divide by zero
Which statement is true? a) Each of C's control statements is characterized as being single-entry, single-exit. b) Each of C's control statements is characterized as being single-entry, multiple-exit. c) Each of C's control statements is characterized as being multiple-en-try, single-exit. d) Each of C's control statements is characterized as being multiple-en-try, multiple-exit.
a) Each of C's control statements is characterized as being single-entry, single-exit.
Flowchart symbols are connected by arrows called __________. a) flowlines b) flow of control c) flow delimiters d) darts
a) flowlines
The __________ is called a single-selection statement. a) if b) when c) if...else d) switch
a) if
The __________ selection statement performs an action if a condition is true and skips that action if the condition is false. a) if b) when c) if...else d) switch
a) if
Bohm and Jacopini's work demonstrated that all programs could be written in terms of only three control statements, namely sequence, __________ and iteration. a) selection b) serialization c) sorting d) searching
a) selection
Which statement is true about the contents of a correct diamond symbol in a correct flowchart. a) It must contain an expression that evaluates to zero or one. b) It must contain a condition or expression that can be either true or false. c) It must contain relational operators. d) It must contain equality operators.
b) It must contain a condition or expression that can be either true or false.
Which statement is false? a) A compound statement can be placed anywhere in a program that a single statement can be placed. b) The if selection statement can have only one statement in its body. c) A set of statements contained within a pair of braces ({and }) is called a compound statement. d) An ifslection statement can have a compound statement in its body.
b) The if selection statement can have only one statement in its body.
Which statement is true? a) Unless directed otherwise, the computer automatically executes C statements one before the other. b) The sequence structure is essentially built into C. c) A flowchart is a pseudocode representation of an algorithm or a por-tion of an algorithm. d) Like pseudocode, flowcharts are useful for developing and repre-senting algorithms, although flowcharts are preferred by most pro-grammers.
b) The sequence structure is essentially built into C.
Placing a semicolon after the parenthesized condition in an ifstatement leads to a __________ error in single-selection if statements and a __________ error in double-selection if statements. a) logic, logic b) logic, syntax c) syntax, logic d) syntax, syntax
b) logic, syntax
A correct decision symbol has __________ flowlines emerging from it. a) 4 b) 3 c) 2 d) 1
c) 2
Any C program we'll ever need to build can be constructed from only __________ different control statements combined in only __________ ways. a) 7, 3 b) 6, 2 c) 7, 2 d) 6, 3
c) 7, 2
Which statement is false? a) Pseudocode helps you "think out" a program before attempting to write it in a programming language such as C. b) Pseudocode programs consist purely of characters so programmers may conveniently type pseudocode programs into a computer using an editor program. c) A carefully prepared pseudocode program is only a beginning; it still takes a tremendous amount of work to convert a pseudocode program into a C program. d) Pseudocode consists only of action statements.
c) A carefully prepared pseudocode program is only a beginning; it still takes a tremendous amount of work to convert a pseudocode program into a C program.
Which statement is false? a) Pseudocode is an artificial and informal language that helps you de-velop algorithms. b) Pseudocode is similar to everyday English. c) Pseudocode is an actual programming language. d) Pseudocode programs are not actually executed on computers.
c) Pseudocode is an actual programming language.
The two key attributes of an algorithm are: a) actions and start activity b) flow and order of flow c) actions and order of actions d) flow and start activity
c) actions and order of actions
Small circle symbols in a flowchart are often called __________ sym-bols. a) little circle b) collision c) connector d) collator
c) connector
Which of the following is not a synonym for "sentinel value." a) signal value b) dummy value c) counter value d) flag value
c) counter value
Counter-controlled iteration is often called __________ iteration be-cause the number of iterations is known before the loop begins execut-ing. a) indefinite b) sentinel c) definite d) determinate
c) definite
The __________ is called a double selection statement. a) if b) when c) if...else d) switch
c) if...else
The __________ selection statement performs an action if a condition is true and performs a different action if the condition is false. a) if b) when c) if...else d) switch
c) if...else
Which of the following statements correctly prints "Passed" if the student's grade is greater than or equal to 60 and "Failed" if the stu-dent's grade is less than 60? [The quotes, of course, should not print.] a) printf("%s\n", grade >= 60 : "Passed" : "Failed"); b) grade >= 60 : puts("Passed ") ? puts("Failed "); c) printf("%s\n", grade >= 60 ? "Passed" : "Failed"); d) grade >= 60 ? puts("Passed ") ? puts("Failed ");
c) printf("%s\n", grade >= 60 ? "Passed" : "Failed");
Various C statements enable you to specify that the next statement to be executed may be other than the next one in sequence. This is called __________. a) change of order b) instruction skipping c) transfer of control d) rerouting
c) transfer of control
Consider the following correct segment of a correct C program: p = 2; while (p < 2000) { p = 2 * p; } What is the value of pafter this while loop completes its execution? a) 1023 b) 1024 c) 2047 d) 2048
d) 2048
Which statement is true? a) With nested control statements, the inner control statement is exe-cuted in sequence after the outer control statement completes its own execution. b) With nested control statements, the inner control statement is exe-cuted exactly once. c) Experience has shown that the most difficult part of solving a prob-lem on a computer is converting an already correct algoithm to a C pro-gram. d) A double-selection statement can be nested in an iteration state-ment.
d) A double-selection statement can be nested in an iteration state-ment.
Which statement is true? a) The expression ++(a + 1) adds 2 to a. b) The expression **a multiplies a by 1. c) The ANSI standard for the C programming language specifies the or-der in which each operator's operands will be evaluated. d) The expression --(abc * 37) is a syntax error
d) The expression --(abc * 37) is a syntax error
The diamond flowcharting symbol is also called the __________ sym-bol. a) determination b) derision c) declarative d) decision
d) decision
Which is not a C iteration statement? a) while b) do...while c) for d) do...for
d) do...for
The __________ flowchart symbol is also called the action symbol. a) small circle b) diamond c) rounded rectangle d) rectangle
d) rectangle
Normally, statements in a program are executed one after the other in the order in which they are written. This is called __________ ex-ecution. a) inline b) seeking c) ordered d) sequential
d) sequential
The __________ is called a multiple selection statement. a) if b) when c) if...else d) switch
d) switch
The __________ selection statement performs one of many different actions, depending on the value of an expression. a) if b) when c) if...else d) switch
d) switch
The C compiler ignores __________ characters like blanks, tabs and newlines used for indentation and vertical spacing. a) transparent b) translucent c) white d) whitespace
d) whitespace