Accounting
Anthropology
Archaeology
Art History
Banking
Biology & Life Science
Business
Business Communication
Business Development
Business Ethics
Business Law
Chemistry
Communication
Computer Science
Counseling
Criminal Law
Curriculum & Instruction
Design
Earth Science
Economic
Education
Engineering
Finance
History & Theory
Humanities
Human Resource
International Business
Investments & Securities
Journalism
Law
Management
Marketing
Medicine
Medicine & Health Science
Nursing
Philosophy
Physic
Psychology
Real Estate
Science
Social Science
Sociology
Special Education
Speech
Visual Arts
Computer Science
Q:
Which statement about a correct for statement with an initialization expression, a loop-continuation test, an increment expression and a loop body is false?
a) The initialization expression is executed only once.
b) The loop-continuation test is evaluated each time through the loop.
c) The initialization is performed each time through the loop.
d) The increment expression is performed after the loop body.
Q:
Which statement regarding for statements is false?
a) In a for statement, the initialization, loop-continuation condition, and increment can contain arithmetic expressions.
b) The increment must be greater than zero.
c) If the loop-continuation condition is initially false, the body of the loop is not performed.
d) It is common to use the control variable for controlling iteration while never mentioning it in the body of the loop.
Q:
If the increment of the for statement is ________ then the loop counts ________.
(a) true, downwards
(b) false, downwards
(c) positive, downwards
(d) negative, downwards
Q:
If the loop-continuation condition in a for statement is initially false, ________.
(a) the body portion of the loop is not performed
(b) execution proceeds with the statement following the for statement
(c) both a and b
(d) none of the above
Q:
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++
d) c + 1 = c
Q:
A programmer intentionally creates a for-loop with the following for header:
for (; ;)
The programmer's intent was most likely to create
a) a syntax error
b) an infinite loop
c) a logic error
d) a divide-by-zero error
Q:
What happens if the loop-continuation test is omitted in a for-statement?
a) C assumes the condition is false, so the loop terminates.
b) A syntax error occurs.
c) C assumes the condition is true, so the loop executes one more time, then terminates.
d) An infinite loop.
Q:
Which statement is false?
a) Comma operators evaluate lists of expressions from right to left.
b) The value of a comma-separated list of expressions is the value of the rightmost expression in the list.
c) The type of a comma-separated list of expressions is the type of the rightmost expression in the list.
d) The comma operator is often used to specify multiple initializations in one particular type of iteration statement.
Q:
The comma operator is most often used in __________ statements.
a) while
b) do while
c) for
d) switch
Q:
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) compilation
c) off-by-one
d) divide-by-zero
Q:
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) <=
Q:
Which of the following is not specified by the following code segment:
for (c = 1; c <= 10; c++)
a) initial value of the loop counter
b) loop continuation test
c) increment of the loop counter
d) body statement of the loop
Q:
Which statement automatically handles all the details of counter-controlled iteration.
a) for
b) while
c) do while
d) continue
Q:
Which statement is generally false?
a) Control counting loops with integer values.
b) Indent the statements in the body of each control statement for clarity.
c) Put a blank line before and after each major control statement to make it stand out in the program.
d) The more deeply nested a program is, the easier it is to understand.
Q:
Which data type should normally not be used to control a counting loop?
a) int
b) float
c) short
d) long
Q:
In the context of counter-controlled iteration, which of the following is not accomplished by the control-variable initialization statement?
int c = 10;
a) Names the control variable.
b) Defines the control variable to be an integer.
c) Specifies the sentinel value.
d) Sets the initial value of the control variable to 10.
Q:
Which is not always required by counter-controlled iteration?
a) The name of a control variable (or loop counter).
b) The initial value of the control variable.
c) The decrement by which the control variable is modified each time through the loop.
d) The condition that tests for the final value of the control variable (i.e., whether looping should continue.
Q:
Which of the following is a poor programming practice?
(a) indenting the statements in the body of each control statement
(b) using floating-point values as the counter in counter-controlled iteration
(c) using more than two levels of nesting
(d) placing vertical spacing above and below control statements
Q:
The statement
while (--counter >= 1) {
printf("%s
", counter % 2 ? "even" : "odd");
}
can not be rewritten as
(a)
while (--counter >= 1) {
if (counter % 2) {
puts("even");
}
else {
puts("odd");
}
}
(b)
while (counter >= 1) {
if (counter % 2) {
puts("even");
}
else {
puts("odd");
}
}
--counter;
(c)while (counter >= 1) {
if (counter % 2) {
puts("even");
}
else {
puts("odd");
}
--counter;
}
(d)
do {
printf("%s
", counter % 2 ? "odd" : "even");
--counter;
} while (counter >= 2);
Q:
Which of the following does counter-controlled iteration not require?
(a) an initial value
(b) a condition that tests for the final value
(c) an increment or decrement by which the control variable is modified each time through the loop
(d) counter controlled iteration requires all of the above
Q:
Which statement is true?
a) Sentinel values are used to control iteration when the precise number of iterations is known in advance.
b) In a counter controlled-loop, the counter may not count downward.
c) Sentinels must be distinct from regular data items.
d) Sentinel-controlled iteration is often called definite iteration.
Q:
Which statement is false?
a) Counter-controlled repetion is sometimes called definite iteration.
b) Sentinel-controlled iteration is sometimes called indefinite iteration.
c) The sentinel value typically indicates "end of data."
d) In counter-controlled iteration, the control variable is always incremented by 1 each time the group of instructions is performed.
Q:
________ iteration is sometimes called indefinite iteration.
(a) counter-controlled
(b) sentinel-controlled
(c) variable-controlled
(d) none of these
Q:
________ iteration is sometimes called definite iteration.
(a) counter-controlled
(b) sentinel-controlled
(c) variable-controlled
(d) none of these
Q:
Which statement is used to skip the remainder of the body of an iteration statement and proceed with the next iteration of the loop?
a) skip
b) proceed
c) continue
d) jump
Q:
Which is not an iteration statement?
a) continue
b) for
c) while
d) do while
Q:
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.
Q:
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.
Q:
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
Q:
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;
Q:
Which of the following will not increment variable c by one?
(a) c + 1;
(b) c++;
(c) ++c;
(d) c += 1;
Q:
Which assignment expression is equivalent to c = c / 2 ?
(a) c / = 2
(b) c / c = 2
(c) c /= 2
(d) c =/ 2
Q:
If x = 3, which of the following sets x to 7?
(a) x *= 4;
(b) x += 4;
(c) x =+ 4;
(d) x + 4 = x;
Q:
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 an iteration statement.
Q:
Having a loop within a loop is known as
(a) recursion
(b) doubling up
(c) nesting
(d) a redundancy
Q:
Which of the following is not a synonym for "sentinel value."
a) signal value
b) dummy value
c) counter value
d) flag value
Q:
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
Q:
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
Q:
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
Q:
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
Q:
Indefinite iteration is controlled by a
(a) counter
(b) sentinel value
(c) data value
(d) non-constant condition
Q:
Counter-controlled iteration is often called __________ iteration because the number of iterations is known before the loop begins executing.
a) indefinite
b) sentinel
c) definite
d) determinate
Q:
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
Q:
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
Q:
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
Q:
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).
Q:
The empty statement is represented by placing __________ where a statement would normally be.
a) empty
b) ;
c) null
d) :
Q:
Placing a semicolon after the parenthesized condition in an if statement 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
Q:
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
Q:
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
", answer == 7 ? "correct" : "incorrect");
(d) answer == 7 ? puts("correct") : puts("incorrect");
Q:
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
Q:
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.
Q:
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
", grade >= 60 : "Passed" : "Failed");
b) grade >= 60 : puts("Passed ") ? puts("Failed ");
c) printf("%s
", grade >= 60 ? "Passed" : "Failed");
d) grade >= 60 ? puts("Passed ") ? puts("Failed ");
Q:
A correct decision symbol has __________ flowlines emerging from it.
a) 4
b) 3
c) 2
d) 1
Q:
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.
Q:
The C compiler ignores __________ characters like blanks, tabs and newlines used for indentation and vertical spacing.
a) transparent
b) translucent
c) white
d) whitespace
Q:
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
Q:
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");
Q:
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
Q:
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.
Q:
Which is not a C iteration statement?
a) while
b) dowhile
c) for
d) dofor
Q:
The __________ is called a multiple selection statement.
a) if
b) when
c) if else
d) switch
Q:
The __________ is called a double selection statement.
a) if
b) when
c) if else
d) switch
Q:
The __________ is called a single-selection statement.
a) if
b) when
c) ifelse
d) switch
Q:
The __________ selection statement performs one of many different actions, depending on the value of an expression.
a) if
b) when
c) ifelse
d) switch
Q:
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) ifelse
d) switch
Q:
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
Q:
The diamond flowcharting symbol is also called the __________ symbol.
a) determination
b) derision
c) declarative
d) decision
Q:
Small circle symbols in a flowchart are often called __________ symbols.
a) little circle
b) collision
c) connector
d) collator
Q:
Flowchart symbols are connected by arrows called __________.
a) flowlines
b) flow of control
c) flow delimiters
d) darts
Q:
The __________ flowchart symbol is also called the action symbol.
a) small circle
b) diamond
c) rounded rectangle
d) rectangle
Q:
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 portion of an algorithm.
d) Like pseudocode, flowcharts are useful for developing and representing algorithms, although flowcharts are preferred by most programmers.
Q:
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
Q:
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
Q:
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
Q:
How many types of control statements exist in C?
(a) 3
(b) 7
(c) 5
(d) 2
Q:
Which of the following is an iteration statement?
(a) if
(b) ifelse
(c) dowhile
(d) switch
Q:
In a flowchart of an algorithm, what is the shape of the decision symbol?
(a) circle
(b) rectangle
(c) diamond
(d) rounded rectangle
Q:
Which of the following encompasses the other three?
(a) sequence structure
(b) iteration structure
(c) control structure
(d) selection structure
Q:
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.