Chapter 3 – C How to Program 6e Multiple Choice Test Bank
Download file with the answers
Chapter 3 - C How to Program 6e Multiple Choice Test Bank
1 file(s) 317.79 KB
Not a member!
Create a FREE account here to get access and download this file with answers
3.1 Introduction
3.2 Algorithms
3.1 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
3.2. 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
3.3 Pseudocode
3.3 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
3.4 Pseudocode does not typically include __________.
(a) definitions
(b) input/output
(c) action statements
(d) control statements
3.5 Which statement is false?
a) Pseudocode is an artificial and informal language that helps you develop algorithms.
b) Pseudocode is similar to everyday English.
c) Pseudocode is an actual programming language.
d) Pseudocode programs are not actually executed on computers.
3.6 Which statement is false?
a) Pseudocode helps you “think out” a program before attempting to write it in a pro-gramming 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 tremen-dous amount of work to convert a pseudocode program into a C program.
d) Pseudocode consists only of action statements.
3.4 Control Structures
3.7 Which of the following encompasses the other three?
(a) sequence structure
(b) repetition structure
(c) control structure
(d) selection structure
3.8 In a flowchart of an algorithm, what is the shape of the decision symbol?
(a) circle
(b) rectangle
(c) diamond
(d) rounded rectangle
ANS: (c)
3.9 Which of the following is a repetition structure?
(a) if
(b) if…else
(c) do…while
(d) switch
3.10 How many types of control structures exist in C?
(a) 3
(b) 7
(c) 5
(d) 2
3.11 Normally, statements in a program are executed one after the other in the order in which they are written. This is called __________ execution.
a) inline
b) seeking
c) ordered
d) sequential
3.12 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
3.13 Bohm and Jacopini’s work demonstrated that all programs could be written in terms of only three control structures, namely sequence, __________ and repetition.
a) selection
b) serialization
c) sorting
d) searching
3.14 Which statement is true?
a) Unless directed otherwise, the computer automatically executes C statements one be-fore the other.
b) The sequence structure is essentially built into C.
c) A flowchart is a pseudocode representation of an algorithm or a portion of an algo-rithm.
d) Like pseudocode, flowcharts are useful for developing and representing algorithms, although flowcharts are preferred by most programmers.
3.15 The __________ flowchart symbol is also called the action symbol.
a) small circle
b) diamond
c) rounded rectangle
d) rectangle
3.16 Flowchart symbols are connected by arrows called __________.
a) flowlines
b) flow of control
c) flow delimiters
d) darts
3.17 Small circle symbols in a flowchart are often called __________ symbols.
a) little circle
b) collision
c) connector
d) collator
3.18 The diamond flowcharting symbol is also called the __________ symbol.
a) determination
b) derision
c) declarative
d) decision
3.19 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
3.20 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
3.21 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
3.22 The __________ is called a single-selection statement.
a) if
b) when
c) if…else
d) switch
3.23 The __________ is called a double selection statement.
a) if
b) when
c) if …else
d) switch
3.24 The __________ is called a multiple selection statement.
a) if
b) when
c) if …else
d) switch
3.25 Which is not a C repetition statement?
a) while
b) do…while
c) for
d) do…for
3.26 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-entry, single-exit.
d) Each of C’s control statements is characterized as being multiple-entry, multiple-exit.
3.27 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
3.5 The if Selection Statement
3.28 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” );
3.29 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 if statement
3.30 The C compiler ignores __________ characters like blanks, tabs and newlines used for indentation and vertical spacing.
a) transparent
b) translucent
c) white
d) whitespace
3.31 Which statement is true about the contents of a correct diamond symbol in a cor-rect 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.
3.32 A correct decision symbol has __________ flowlines emerging from it.
a) 4
b) 3
c) 2
d) 1
3.33 Which of the following statements correctly prints “Passed” if the student’s grade is greater than or equal to 60 and “Failed” if the student’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 ” );
3.34 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 if slection statement can have a compound statement in its body.
3.6 The if…else Selection Statement
3.35 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
3.36 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” : “incorrect” );
(d) answer == 7 ? puts( “correct” ) : puts( “incorrect” );
3.37 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
3.38 Placing a semicolon after the parenthesized condition in an if statement leads to a __________ error in single-selection if statements and a __________ error in dou-ble-selection if statements.
a) logic, logic
b) logic, syntax
c) syntax, logic
d) syntax, syntax
3.39 The empty statement is represented by placing __________ where a statement would normally be.
a) empty
b) ;
c) null
d) :
3.7 The while Repetition Statement
3.40 What is wrong with the following while loop?
while (sum <= 1000)
sum = sum + 30;
(a) The parenthesis should be braces.
(b) Braces are required around sum = sum +30;.
(c) While should be while.
(d) There should be a semicolon after While ( sum <=1000 ).
3.41 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
3.42 Consider the following correct segment of a correct C program:
p = 2;
while ( p < 2000 )
p = 2 * p;
What is the value of p after this while loop completes its execution?
a) 1023
b) 1024
c) 2047
d) 2048
3.8 Formulating Algorithms Case Study 1: Counter-Controlled Repetition
3.43 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
3.44 Counter-controlled repetition is often called __________ repetition because the number of repetitions is known before the loop begins executing.
a) indefinite
b) sentinel
c) definite
d) determinate
3.9 Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 2: Sentinel-Controlled Repetition
3.45 Indefinite repetition is controlled by a
(a) counter
(b) sentinel value
(c) data value
(d) non-constant condition
3.46 A fatal logic error is always caused by:
(a) not initializing variables before executing a repetition 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
3.47 In indefinite repetition, 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
3.48 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.25
(b) 5.5
(c) 5
(d) 8
3.49 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
3.50 Which of the following is not a synonym for “sentinel value.”
a) signal value
b) dummy value
c) counter value
d) flag value
3.10 Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 3: Nested Control Statements
3.51 Having a loop within a loop is known as
(a) recursion
(b) doubling up
(c) nesting
(d) a redundancy
3.52 Which statement is true?
a) With nested control statements, the inner control statement is executed in sequence after the outer control statement completes its own execution.
b) With nested control statements, the inner control statement is executed exactly once.
c) Experience has shown that the most difficult part of solving a problem on a computer is converting an already correct algoithm to a C program.
d) A double-selection statement can be nested in a repetition statement.
3.11 Assignment Operators
3.53 If x = 3, which of the following sets x to 7?
(a) x *= 4;
(b) x += 4;
(c) x =+ 4;
(d) x + 4 = x;
3.54 Which assignment expression is equivalent to c = c / 2 ?
a) c / = 2
b) c / c = 2
c) c /= 2
d) c =/ 2
3.12 Increment and Decrement Operators
3.55 Which of the following will not increment variable c by one?
(a) c + 1;
(b) c++;
(c) ++c;
(d) c += 1;
3.56 In which of the following is y not equal to 5 after execution? Assume that x is equal to 4.
(a) y = 5;
(b) y = x++;
(c) y = ++x;
(d) y = x = 5;
3.57 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 order in which each operator’s operands will be evaluated.
d) The expression –(abc * 37) is a syntax error
3.13 Secure C Programming
3.58 Which of the following statements is true about undefined behavior, which can leave a system open to attack?
(a) It’s not possible to have undefined behavior when adding two integers.
(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.
3.59 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.
Leave a reply