You are on page 1of 76

LOTS OF SAMPLE QUESTIONS FOR YOUR CSC-226 MIDTERM CAUTION: I DID NOT WRITE THESE QUESTIONS, SO SOME OF THEM

ARE POORLY WORDED AND SOME OF THEM EVEN CONTAIN ERRORS. WE WILL CONCENTRATE ONLY ON SOME OF THE QUESTIONS FOR OUR REVIEW. AT LEAST REVIEW THE QUESTIONS MARKED IN RED.

1.1 Int !"#$t%!n


1.1 Which of the following statements is true? (a) hardware controls software (b) software commands the computer to perform actions and make decisions (c) Pascal and C are object oriented programming languages (d) ANSI is the international standards institute ANS: (b) 1.2 Which of the following is going to be the key programming methodology for the next decade? (a) object-oriented programming (b) structured programming (c) legacy C code (d) live-code approach ANS: (a)

1.2 W&'t %( ' C!)*#t+ ,


1.3 Today's fastest computers are called __________. (a) mega computers (b) terminals (c) supercomputers (d) CPUs ANS: (c)

1.4 Which of the following would not be considered hardware? (a) an operating system (b) a CPU

(c) a keyboard (d) a disk ANS: (a) 1.5 Computer programs are __________. (a) sets of control instructions (b) the information processed by the computer (c) the various devices (disks, memory, keyboard) that comprise a computer system (d) the people programming the computers ANS: (a)

1.- C!)*#t+ O .'n%/'t%!n


1.6 Which of the following is not one of the six logical units of a computer? (a) input unit (b) programmer unit (c) memory unit (d) output unit ANS: (b) 1.7 The central processing unit (CPU) __________. (a) retains information so that the information can be readily available for processing. (b) performs calculations such as addition, subtraction, multiplication, and division. (c) supervises the operation of the other sections. (d) obtains information from input devices and places it at the disposal of other units. ANS: (c) 1.8 Programs or data not actively being used by the other units are placed on the __________. (a) output unit. (b) memory unit. (c) secondary storage unit. (d) central processing unit. ANS: (c)

1.0 E1!2#t%!n !3 O*+ 't%n. S4(t+)(


1.9 (a) (b) (c) The amount of work a computer can process is known as __________. input output distribution

(d) throughput ANS: (d)

1.10 If a program is made to share the resources of the computer with other programs, this is known as __________. (a) batch processing (b) multiprogramming (c) client/server computing (d) object-oriented programming ANS: (b)

1.5 P+ (!n'2 C!)*#t%n., D%(t %6#t+" C!)*#t%n. 'n" C2%+nt7S+ 1+ C!)*#t%n.


1.11 When computing is spread over networks rather than performed at a centralized location, this is known as __________. (a) multiprogramming (b) distributed computing (c) personal computing (d) batch processing ANS: (b)

1.12 Programs and data used in client/server computing are stored on __________. (a) personal computers (b) supercomputers (c) file servers (d) local area networks ANS: (c)

1.6 M'$&%n+ L'n.#'.+(, A((+)624 L'n.#'.+(, 'n" H%.&-2+1+2 L'n.#'.+(


1.13 Which of the following is not a general programming language type? (a) machine languages (b) low-end languages (c) assembly languages (d) high-level languages ANS: (b)

1.14 A computer can directly understand only its own ___________. (a) machine language (b) assembly language (c) high-level language (d) none of the above ANS: (a) 1.15 Assemblers__________. (a) convert machine language into high-level language. (b) convert assembly language into machine language. (c) convert high-level language into machine language. (d) convert high-level language into assembler language. ANS: (b) 1.16 Programs that directly execute high-level language programs without compiling are called __________. (a) assemblers (b) interpreters (c) compilers (d) translators ANS: (b)

1.8 T&+ H%(t! 4 !3 C


1.17 Which of the following languages was an ancestor of C? (a) A (b) A+ (c) B (d) B+ ANS: (c)

1.9 T&+ C St'n"' " L%6 ' 4


1.19 When programming in C you will typically use all of the following building blocks except __________. (a) functions from the standard library (b) functions you create yourself (c) functions other people have created for you

(d) functions provided by ANSI / ISO ANS: (d)

1.20 Using standard library functions can be more efficient because __________. (a) they save programming time (b) they are carefully written to perform optimally (c) they increase program portability (d) all of the above. ANS: (d)

1.: T&+ K+4 S!3t;' + T +n": O6<+$t T+$&n!2!.4


1.21 Which of the following is not an advantage of object-oriented programming? (a) software is more reusable (b) software is more understandable and easier to maintain (c) programmers are able to model the real world (d) all of the above are advantages of object-oriented programming ANS: (d)

1.1= C>> 'n" C++ How to Program


1.22 ________ are essentially reusable software components that model items in the real world. (a) objects (b) supersets (c) modules (d) developers ANS: (a) 1.23 C++ was developed by ________. (a) Bjarne Stroustrup (b) Ada Lovelace (c) Blaise Pascal (d) Ken Thompson ANS: a

1.11 ?'1' 'n" Java How to Program


1.24 Java was developed by ___________. (a) Sun Microsystems

(b) Bell Labs (c) IBM (d) ANSI/ISO ANS: (a) 1.25 What language(s) Java is based on? (a) B and BCPL (b) C and C++ (c) Smalltalk (d) FORTRAN ANS: (b)

1.12 Ot&+ H%.&-2+1+2 L'n.#'.+(


1.26 Which of the following is not true about COBOL? (a) it stands for common business oriented language. (b) more than half of all business software is programmed in it. (c) it was developed in 1992. (d) COBOL is used for commercial applications that require precise and efficient manipulation of large amounts of data. ANS: (c)

1.27 Which popular language was developed by IBM Corporation to be used for scientific and engineering applications that require complex mathematical computations? (a) Smalltalk (b) Pascal (c) FORTRAN (d) COBOL ANS: (c)

1.1- St #$t# +" P !. '))%n.


1.28 Pascal was designed for what purpose? (a) scientific and engineering applications requiring complex mathematical computations (b) commercial applications requiring precise and efficient manipulation of large amounts of data (c) teaching structured programming in academic environments (d) the DOD ANS: (c)

1.29 Performing many activities that occur in parallel is known as ___________. (a) compiling (b) distributed computing (c) batch processing (d) multitasking ANS: (d)

1.10 @'(%$( !3 ' T4*%$'2 C En1% !n)+nt


1.30 The compile stage is when ____________. (a) the object code is linked with code for functions in other files (b) the C program is translated into machine language code (c) the program is executed one instruction at a time (d) the program is placed in memory ANS: (b)

1.31 The linker creates __________. (a) an executable image (b) a preprocessor directive (c) object code (d) an input stream ANS: (a)

1.15 H' ";' + T +n"(


1.32 Over the past decades which of the following has occurred? (a) hardware costs have fallen rapidly (b) software costs have fallen rapidly (c) hardware costs have risen rapidly (d) none of the above ANS: (a)

1.33 The invention of the __________ in the late 1970s and 1980s laid the groundwork for the productivity improvements of the 1990s. (a) transistor (b) c (c) inexpensive hardware

(d) microprocessor chip ANS: (d)

1.16 H%(t! 4 !3 t&+ Int+ n+t


1.34 An ancestor of today's Internet was _____________. (a) ARPAnet (b) e-mail (c) FORTRAN (d) Univac 1108 ANS: (a) 1.35 The technique by ARPA to allow multiple users to send and receive information at the same time over the same communications paths is known as ___________. (a) electronic mail (b) packet switching (c) networking (d) multitasking ANS: (b) 1.36 What is bandwidth? (a) information carrying capacity (b) response time (c) the set of networking protocols (d) an error-control technique ANS: (a)

1.18 H%(t! 4 !3 t&+ W! 2" W%"+ W+6


1.37 The World Wide Web (a) was developed at roughly the same time as the Internet (b) paved the way for the Internet (c) was developed years after the Internet (d) was designed for stand-alone computers ANS: (c)

1.19 A+n+ '2 N!t+( A6!#t C 'n" T&%( @!!B


1.38 What does KIS stands for? (a) Keep In Sync

(b) Keep It Simple (c) Keep Iterating Stuff (d) Keyword Interpreted Sequence ANS: (b)

2.1 Int !"#$t%!n 2.2 A S%)*2+ P !. '): P %nt%n. ' L%n+ !3 T+Ct 2.1 Lines beginning with the _______________ let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d) << ANS: (a) 2.2 Which of the following must every C++ program have? (a) main (b) #include (c) // (d) <stdio.h> ANS: (a) 2.3 Every statement in C must end with a (a) period (.) (b) semicolon (;) (c) colon (:) (d) backslash (/) ANS: (b) 2.4 Which of the following is not a valid escape sequence? (a) \n (b) \\ (c) \~ (d) \ ANS: (c) 2.5. Which statement about comments is false? a) Comments begin and end with /* and */, respectively. b) Programmers insert comments to document programs and improve

program readability. c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. ANS: (d) 2.6. Lines beginning with a # are processed a) at execution time b) at compile time c) at preprocessor time d) at postprocessor time ANS: (c) 2.7. hich o! the !ollowing statements about the inclusion o! <stdio.h> is !alse" a) #t is re$uired. b) %his header !ile contains in!ormation and declarations used b& the compiler when compiling standard input'output librar& !unctions such as printf. c) %his header !ile contains in!ormation that helps the compiler determine i! calls to librar& !unctions ha(e been made correctl&. d) %his header helps locate bugs in &our program at compile time) rather than at execution time (when errors are usuall& more costl& to correct. ANS: (a) 2.*. #n the line
int main !

the parentheses indicate that main is a program building bloc+ called a a) module b) statement c) method d) !unction ANS: (d) 2.,. %he pair o! braces that delineate the bod& o! main and the portion o! the program between these braces is called a ----------.

a) !unction b) bloc+ c) statement d) header ANS: (b) 2../. hich o! the !ollowing is not a s&non&m !or a 0 string" a) message b) character string c) character d) literal ANS: (c) 2.... %he !ollowing line is most properl& an example o! a ----------.
printf "#elcome to $% !

a) !unction b) bloc+ c) statement d) header ANS: (c) 2..2. #n a printf) a bac+slash is printed b& enclosing in $uotes a) \ b) \\ c) /\ d) // ANS: (b) 2..1. A lin+ed program is o!ten called a(n) ----------. a) chain b) librar& c) ob2ect d) executable ANS: (d) 2..3. %he escape se$uence !or hori4ontal tab is ----------. a) \t a&

b) \t c) \hori'ontalta& d) \t ANS: (b)

2.- An!t&+ S%)*2+ P !. '): A""%n. T;! Int+.+ ( 2.15 Which of the following is not a valid integer value? (a) () (b) * (c) +,)-./0 (d) ,., ANS: (d)

2.16 Which of the following is an invalid identifier (variable name)? (a) 12est (b) 2E32 (c) /test (d) test, ANS: (c) 2.17 Which statement prints hi on the screen? (a) printf 4hi4!; (b) print 4hi4; (c) printf 4hi4; (d) none of the above ANS: (a) 2.18 The __________ sign is also known as the __________ operator. (a) 5, assignment (b) 6, assignment (c) *, stream manipulator (d) 7, stream insertion ANS: (b) 2.19. A(n) __________ is a location in the computer's memory where a

value can be stored for use by a program. a) unknown b) name c) variable d) declaration ANS: (c) 2.20. Which statement is false. a) Variables may be defined anywhere in the body of main. b) All variables must be defined. c) All variable definitions must include the name and data type of each variable. d) Several variable of the same data type may be defined in one definition. ANS: (a) 2.21. Which of these is not a valid identifier? a) a18alid1identifier b) a,18alid1identifier c) a18alid1identifier1 d) ,18alid1identifier ANS: (d) 2.22. Which of the following statements is false? a) C is case sensitive. b) Uppercase and lowercase letters are different in C. c) identifier and IdEnTiFiEr are identical identifiers in C. d) Identifiers can be of any length ANS: (c) 2.23. Which of the following multiple word variable names does not conform to the good programming practices in the text? a) multiple19ord18aria&le1name b) multiple#ord:aria&le;ame c) multiple9ord8aria&lename d) aReall<Reall<=on>Multiple#ord:a ANS: (c) 2.24. A(n) __________ error is caused when the compiler can not recognize a statement.

a) sin tax b) syntax c) linkage d) execution ANS: (b) 2.25. The address operator is a) 77 b) ? c) @ d) 7 ANS: (d) 2.26. Which statement is false? a) in the statement
sum 6 inte>er, 5 inte>er+;

both 6 and 5 are binary operators. b) The statement in part a) is an example of an assignment statement; c) The spaces around each of the binary operators in the statement of part a) are required. d) The calculation in part a) occurs correctly on the right hand side of the = operator. ANS: (c) 2.27. Which of the following is false? a) Each variable being input in a scanf statement is generally preceded by an 7. b) Each variable being output in a printf statement is generally not preceded by an 7. c) In a printf statement place inside the format control string the comma that separates the format control string from the expressions to be printed. d) In a printf statement, preceding the name of a variable to be printed prints the address of that variable. ANS: (c)

2.0 M+)! 4 C!n$+*t( 2.28 Variable names actually correspond to __________. (a) locations in the computer's memory (b) operators (c) integers (d) data types ANS: (a) 2.28 When a number gets assigned to a variable that already has a value __________. (a) the new number overwrites the previous value at that memory location (b) the new number gets assigned to a neighboring memory location (c) the computer issues an error (d) the new value is destroyed and the old value remains
ANS: D'E

2.1/. 5(er& (ariable has all the attributes below) except a) name b) (alue c) alias d) t&pe ANS: (c) 2.1.. hich o! the !ollowing is !alse" a) 6eading a (alue into a memor& location destro&s the pre(ious (alue. b) 6eading a (alue out o! a memor& location destro&s that (alue. c) sum 6 inte>er, 5 inte>er+; in(ol(es destructi(e read7in. d) %he statement in part c) also in(ol(es nondestructi(e read7out.
ANS: D6E

2.5 A %t&)+t%$ 2.32 Which operation will find the remainder when 15 is divided by 6? (a) ,/ / A (b) ,/ ? A (c) ,/ B A

(d) ,/ * A ANS: (b) 2.33 Evaluate the expression


) * - ? A 5 - */

(a) 20 (b) 26 (c) 12 (d) 32 ANS: (a) 2.13. hich statement is !alse" a) #n algebra) we write ab to multipl& a times b. b) #n 0) we write a& to multiple a times &. c) #n 0) the modulus operator is ?. d) #n 0) integer di(ision &ields an integer result. ANS: (b) 2.18. hich statement about 0 arithmetic is !alse" a) 6 ' 1 &ields 2 b) 8 ' 2 &ields 2.8 c) 7 9 1 &ields . d) 6 9 1 &ields / ANS: (b) 2.16. a : (b ; c) ma& also be written in 0 as a) a& 5 ac b) a * & ! 5 c c) a * & 5 c d) a * & 5 a * c ANS: (d) 2.17. hich statement about precedence is !alse" a) <arentheses ma& be used to !orce the order o! e(aluation to occur in an& se$uence desired b& the programmer. b) Nested) or embedded parentheses are e(aluated last. c) =ultiplication has a higher precedence than addition. d) Subtraction has a lower precedence than di(ision. ANS: (b)

2.1*. hich expression is true" a) %he expression a * & 5 c! 5 c * d 5 e! contains nested parentheses. b) %he expression < 6 a * C * C 5 & * C 5 c is a second degree pol&nomial. c) %he 0 standard librar& pro(ides !unction po9er to per!orm exponentiation. d) hen we sa& e(aluation o! an expression proceeds !rom le!t to right we are re!erring to the additi(it& o! the operators. ANS: (b) 2.6 D+$%(%!n M'B%n.: EF#'2%t4 'n" R+2't%!n'2 O*+ 't! ( 2.39 C's if statement executes the statement inside its body if a specified __________ is __________. (a) condition, true (b) condition, false (c) equality operator, true (d) relational operator, true ANS: (a) 2.40 Which of the following is an equality operator? (a) 66 (b) 6 (c) > (d) >6 ANS: (a) 2.41. Which statement is false? a) Executable C statements either perform actions or make decisions. b) If the condition in an if statement is met, the statement in the body of the if statement is executed. c) All the relational operators have the same level of precedence. d) The equality operators have a higher level of precedence than the relational operators. ANS: (d)

2.42. Which statement is false? a) The relational operators associate left to right. b) An execution time error will occur if the two symbols in any of the operators ==, !=, >= and <= are separated by spaces. c) Confusing the == operator with = operator is typically an error. d) The equality operators associate left to right. ANS: (b) 2.43. Which statement is false? a) Whitespace characters such as tabs, newlines and spaces are generally ignored by the C compiler. b) The statements in an if statement must be indented. c) Placing a blank line before and after every control structure can improve program readability. d) There can be (but should not be) more than one statement per line. ANS: (b) 2.44. Which statement is false? a) It is not correct to split an identifier with a space, a tab or a newline. b) Statements and comments may be split over several lines. c) The equals sign (6) is not an operator. d) A correct place to break a line is after a comma in a comma-separated list. ANS: (c) 2.45. Which of the following is not a keyword? a) int b) return c) if d) main ANS: (d) 2.46. Which statement is false? a) The assignment operator associates from left to right. b) The arithmetic operators associate from left to right. c) The equality operators associate from left to right. d) The relational operators associate from left to right. ANS: (a)

2.47. The order in which statements are __________ is called flow of control. a) entered in a source file b) preprocessed c) compiled d) executed ANS: (d) 2.48. Which is not a keyword? a) re>ister b) 8olatile c) eCternal d) struct ANS: (c)

-.1 Int !"#$t%!n -.2 A2.! %t&)(


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 ANS: (c) 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 ANS: (c)

-.- P(+#"!$!"+
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 include definitions and all types of statements (d) all of the above are false ANS: (b) 3.4 Pseudocode does not include __________. (a) definitions (b) input/output (c) algorithms (d) control structures ANS: (a) 3.5. Which statement is false? a) Pseudocode is an artificial and informal language that helps programmers 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.

ANS: (c) 3.6. Which statement is false? a) Pseudocode helps the programmer 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. ANS: (c)

-.0 C!nt !2 St #$t# +(


3.7 Which of the following encompasses the other three? (a) sequence structure (b) repetition structure (c) control structure (d) selection structure ANS: (c) 3.8 In a flowchart of an algorithm, what is the shape of the decision symbol? (a) circle (b) rectangle (c) diamond (d) oval ANS: (c) 3.9 Which of the following is a repetition structure? (a) if (b) ifDelse (c) doD9hile (d) s9itch ANS: (c) 3.10 How many types of control structures exist in C? (a) 3 (b) 7 (c) 5 (d) 2 ANS: (a) 3.11. Normally, statements in a program are eexecuted one after the other in the order in which they are written. This is called __________ execution.

a) inline b) seeking c) ordered d) sequential ANS: (d) 3.12. Various C statements enable the programmer 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 ANS: (c) 3.13. Bohm and Jacopinis 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 ANS: (a) 3.14. 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. ANS: (b) 3.15. The __________ flowchart symbol is also called the action symbol. a) small circle b) diamond c) oval d) rectangle ANS: (d) 3.16. Flowchart symbols are connected by arrows called __________. a) flowlines b) flow of control c) flow delimiters d) darts ANS: (a)

3.17. Small circle symbols in a flowchart are often called __________ symbols. a) little circle b) collision c) connector d) collator ANS: (c) 3.18. The diamond flowcharting symbol is also called the __________ symbol. a) determination b) derision c) declarative d) decision ANS: (d) 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) 9hen c) if Delse d) s9itch ANS: (a) 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) 9hen c) if Delse d) s9itch ANS: (c) 3.21. The __________ selection statement performs one of many different actions, depending on the value of an expression. a) if b) 9hen c) if Delse d) s9itch ANS: (d) 3.22. The __________ is called a single selection structure. a) if b) 9hen c) if Delse d) s9itch ANS: (a) 3.23. The __________ is called a double selection structure.

a) if b) 9hen c) if Delse d) s9itch ANS: (c) 3.24. The __________ is called a multiple selection structure. a) if b) 9hen c) if Delse d) s9itch ANS: (d) 3.25. Which is not a repetition structure? a) 9hile b) do D9hile c) for d) do Dfor ANS: (d) 3.26. Which statement is true? a) Each of Cs control structures is characterized as being single-entry, single-exit. b) Each of Cs control structures is characterized as being single-entry, multiple-exit. c) Each of Cs control structures is characterized as being multiple-entry, single-exit. d) Each of Cs control structures is characterized as being multiple-entry, multiple-exit. ANS: (a) 3.27. Any C program we will ever need to build can be constructed from only __________ different types of control structures combined in only __________ ways. a) 7, 3 b) 6, 2 c) 7, 2 d) 6, 3 ANS: (c)

-.5 T&+ %3 S+2+$t%!n St't+)+nt


3.28. If grade has the value of 60 what will the following code print?
if >rade >6 A* ! printf "Eassed!;

(a) (b) (c) (d)

nothing
A* Eassed printf "Eassed!;

ANS: (c) 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 ANS: (b) 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 ANS: (d)

3.31. Which statement is true about the contents of a correct diamond symbol in a correct flowchart. a) It must contain a condition that explicitly evaluates to true or false b) It may contain a condition that can be either true or false. c) It must contain relational operators. d) It must contain equality operators. ANS: (b) 3.32. A correct decision symbols has __________ flowlines emerging from it. a) 4 b) 3 c) 2 d) 1 ANS: (c) 3.33. Which of the following statements correctly prints Passed if the students grade is greater than or equal to 60 and Failed if the students grade is less than 60? [The quotes, of course, should not print.] a) printf "?s\nF >rade >6 A* : "Eassed : "Gailed !; b) >rade >6 A* : printf "Eassed\n ! H printf "Gailed\n !; c) printf "?s\nF >rade >6 A* H "Eassed : "Gailed !; d) >rade >6 A* H printf "Eassed\n ! H printf "Gailed\n !; ANS: (c) 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 ( I and J) is called a compound statement. d) An if slection statement can have a compound statement in its body. ANS: (b)

-.6 T&+ %3G+2(+ S+2+$t%!n St't+)+nt


3.35 The conditional operator (H:) ________. (a) is the only ternary operator in C (b) is a unary operator (c) associates from left to right (d) accepts two operands ANS: (a) 3.36 Which of the following will generate an error? (a) if ans9er 66 K !
printf else printf "incorrect !; "correct !;

(b) printf ans9er 66 K H "correct : "incorrect !; (c) printf ans9er 66 K H "correct : "incorrect !; (d) ans9er 66 K H printf "correct ! :
printf "incorrect !;

ANS: (b) 3.37 A statement is called a block ________. (a) if it is a compound statement (b) if it contains definitions (c) if it is a compound statement that contains definitions (d) if it does not contain definitions ANS: (c) 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 doubleselection if statements. a) logic, logic b) logic, syntax c) syntax, logic d) syntax, syntax ANS: (b) 3.39. The empty statement is represented by placing __________ where a statement would normally be.

a) empt< b) ; c) null d) : ANS: (b) 3.40. Which statement is false? a) A compound statement may contain definitions. b) A block may optionally contain definitions. c) A block that contains definitions can be used anywhere that a compound statement can be used. d) A compound statement that contains definitions is called a block ANS: (b)

-.8 T&+ ;&%2+ R+*+t%t%!n St't+)+nt


3.41 What is wrong with the following while loop?
#hile sum <6 ,***! sum 6 sum 5 )*;

(a) The parenthesis should be braces. (b) Braces are required around sum 6 sum 5)*;. (c) #hile should be 9hile. (d) There should be a semicolon after #hile sum <6,*** !. ANS: (c) 3.42 How many times will the following program print hello?
i 6 ,; 9hile i <6 ,* ! printf "hello !;

(a) 10 (b) 8 (c) an infinite number of times (d) 0 ANS: (c) 3.43. Consider the following correct segment of a correct C program:
p 6 +; 9hile p < +*** ! p 6 + * p; What is the value of p after this while loop completes its execution?

a) 1023 b) 1024 c) 2047 d) 2048 ANS: (d)

-.9 F! )#2't%n. A2.! %t&)(: C'(+ St#"4 1 DC!#nt+ -C!nt !22+" R+*+t%t%!nE
3.44 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 ANS: (a) 3.45. 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 ANS: (c)

-.: F! )#2't%n. A2.! %t&)( ;%t& T!*-D!;n, St+*;%(+ R+3%n+)+nt: C'(+ St#"4 2 DS+nt%n+2-C!nt !22+" R+*+t%t%!nE
3.46 Indefinite repetition is controlled by a (a) counter (b) sentinel value (c) data value (d) non-constant condition ANS: (b) 3.47 A fatal logic error is always caused by: (a) not initializing variables before executing a repetition structure (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 ANS: (d) 3.48 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 ANS: (a)

3.49 What is the final value of C after performing the following operations?
int C 6 +,; dou&le < 6 A; dou&le ' 6 ,-; < 6 C / '; C 6 /./ * <;

(a) 8.25 (b) 5.5 (c) 5 (d) 8 ANS: (d) 3.50 Which operation does not take place in the following example?
int C 6 +,; dou&le < 6 A; dou&le ' 6 ,-; < 6 C / '; C 6 /./ * <;

(a) implicit conversion (b) promotion (c) explicit conversion (d) truncation ANS: (c) 3.51. Which of the following is not a synonym for sentinel value. a) signal value b) dummy value c) counter value d) flag value ANS: (c)

-.1= F! )#2't%n. A2.! %t&)( ;%t& T!*-D!;n, St+*;%(+ R+3%n+)+nt: C'(+ St#"4 - DN+(t+" C!nt !2 St #$t# +(E
3.52 Having a loop within a loop is known as (a) recursion (b) doubling up (c) nesting (d) a redundancy ANS: (c)

3.53. Which statement is true? a) With nested control structures, the inner control structure is executed in sequence after the outer control structure completes its own execution. b) With nested control structures, the inner control structure 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 structure can be nested in a repetition structure. ANS: (d)

-.11 A((%.n)+nt O*+ 't! (


3.54 If C 6 ), which of the following sets C to K? (a) C *6 -; (b) C 56 -; (c) C 65 -; (d) C 5 - 6 C; ANS: (b) 3.55. Which assignment expression is equivalent to c 6 c / + ? a) c / 6 + b) c / c 6 + c) c /6 + d) c 6/ + ANS: (c)

-.12 In$ +)+nt 'n" D+$ +)+nt O*+ 't! (


3.56 Which of the following will not increment variable c by one? (a) c 5 ,; (b) c55; (c) 55c; (d) c 56 ,; ANS: (a) 3.57 In which of the following is < not equal to / after execution? C is equal to -. (a) < 6 /; (b) < 6 C55; (c) < 6 55C; (d) < 6 C 6 /; ANS: (c) 3.58 Which statement is true?

a) The expression 55 a 5 ,! adds + to a. b) The expression **a multiplies a by ,. c) The ANSI standard for the C programming language specifies the order in which each operators operands will be evaluated. d) The expression (( a&c * )K! is a syntax error ANS: (d)

0.1 Int !"#$t%!n 4.1. Which is not a repetition struction? a) continue b) for c) 9hile d) do 9hile ANS: (a) 4.2.Which statement is used to skip the remainder of the body of a repetition struction and proceed with the next iteration of the loop? a) sLip b) proceed c) continue d) Mump ANS: (c) 0.2 T&+ E((+nt%'2( !3 R+*+t%t%!n 4.3 ________ repitition is sometimes called definite repitition. (a) counter-controlled (b) sentinel-controlled (c) variable-controlled (d) none of these ANS: (a) 4.4 ________ repitition is sometimes called indefinite repitition. (a) counter-controlled (b) sentinel-controlled (c) variable-controlled (d) none of these ANS: (b)

4.5. Which statement is false? a) Counter-controlled repetion is sometimes called definite repetition. b) Sentinel-controlled repetition is sometimes called indefinite repetition. c) The sentinel value typically indicates end of data.

d) In counter-controlled repetition, the control variable is always incremented by 1 each time the group of instructions is performed. ANS: (d) 4.6. Which statement is true? a) Sentinel values are used to control repetition when the precise number of repetitions is known in advance. b) Sentinel values are used to control repetition when the loop does not include statements that obtain data each time the loop is performed. c) Sentinels must be distinct from regular data items. d) Sentinel-controlled repetition is often called definite repetition. ANS: (c)

0.- C!#nt+ -C!nt !22+" R+*%t%t%!n 4.7 Which of the following does counter controlled repetition 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 repetition requires all of the above ANS: (d) 4.8 The statement
9hile (( counter >6 , ! printf "?s\nF counter ? + H "e8en : "odd !;

can not be rewritten as (a) 9hile (( counter


if else printf

>6 , ! counter ? + ! printf "e8en !; "odd !;

(b)

9hile if else

counter >6 , ! counter ? +! printf "e8en !; "odd !;

printf ((counter;

(c)

9hile I

counter >6 , !

if else

counter ? + ! printf "e8en !; "odd !;

printf ((counter; J

(d)
I

do

printf "?s\nF counter ? + H "odd : "e8en !; ((counter; J9hile counter >6 + !;

ANS: (b) 4.9 Which of the following is a bad programming practice? (a) indenting the statements in the body of each control structure (b) using floating-point values as the counter in counter-controlled repetition (c) using more than three levels of nesting (d) placing vertical spacing above and below control structures ANS: (b)

4.10. Which is not always required by counter-controlled repetition? 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. ANS: (c) 4.11. In the context of counter-controlled repetition, 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; ANS: (c)

4.12. Which data type should normally not be used to control a counting loop? a) int b) float c) short d) lon> ANS: (b) 4.13. Which statement is generally false? a) Control counting loops with integer values. b) Indent the statements in the body of each control structure for clarity. c) Put a blank line before and after each major control structure to make it stand out in the program. d) The more deeply nested a program is, the easier it is to understand. ANS: (d)

0.0 T&+ 3! R+*+t%t%!n St't+)+nt 4.14 Which of the following is not true? (a) the three expressions in the for statement are optional. (b) the initialization and increment expressions can be comma-seperated lists. (c) you must define the control variable outside of the for loop. (d) All of the above are true. ANS: (c)

4.15. Which statement automatically handles all the details of countercontrolled repetition. a) for b) 9hile c) do 9hile d) continue ANS: (a) 4.16. Which of the following is not specified by the following correct 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 ANS: (d) 4.17. A programmer writes a for statement to count from , to ,* and explicitly mentions the , and the ,* in the for header. Which relational operator would probably be used in the loop-continuation test? a) > b) >6 c) < d) <6 ANS: (d) 4.18. Using an incorrect relational operator or using an incorrect final value of a loop counter in the condition of a 9hile or for statement is a frequent cause of __________errors. a) syntax b) compilation c) off-by-one d) divide-by-zero ANS: (c) 4.19. The comma operator is most often used in __________ statements. a) 9hile b) do 9hile c) for d) s9itch ANS: (c) 4.20. 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 repetition structure. ANS: (a) 4.21. What happens if the loop-continuation test is omitted in a forstatement? 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. ANS: (d) 4.22. Omitting the expression before the first required semi-colon in a for header is likely to cause a(n) __________ error. a) syntax b) infinite loop c) logic d) divide-by-zero ANS: (c) 4.23. A program contains a for-loop with the following for header. The programmers intent was most likely to create a) a syntax error b) an infinite loop c) a logic error d) a divide-by-zero error ANS: (b) 4.24. Which of the following is an incorrect expression to increment c by , in the increment expression of a for header? a) c 56 , b) 55c c) c55 d) c 5 , 6 c ANS: (d) 0.5 T&+ 3! St't+)+nt: N!t+( 'n" O6(+ 1't%!n( 4.25 If the loop-continuation condition 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 ANS: (c) 4.26 If the increment of the for statement is ________ then the loop counts ________. (a) true, downwards (b) false, downwards (c) positive, downwards (d) negative, downwards ANS: (d)

4.27. 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 repetition while never mentioning it in the body of the loop. ANS: (b) 4.28. 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 incrementing is performed each time through the loop. 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. ANS: (c) 0.6 EC')*2+( U(%n. t&+ 3! St't+)+nt 4.29 Which of the following for headers is not valid? (a) for int i 6 *; i < ,*; i55 ! (b) int i;

for

; i < ,*; i55 !

(c) (d)

int i; for ; ; i55! int i; ; i < ,*; !

for

ANS: (c) 4.30 Float and double variables should be used (a) to perform monetary calculations. (b) as counters. (c) with relational operators. (d) as imprecise representations of numbers. ANS: (d)

4.31. The for statement header


for i 6 ,; i < ,**; i55 !

performs the body of the loop for a) values of the control variable from , to ,** in increments of 1. b) values of the control variable from , to 00 in increments of 1. c) values of the control variable from * to ,** in increments of 1. d) values of the control variable from , to 00 in increments of 1. ANS: (b) 4.32. 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 ANS: (b) 4.33. What is produced by a for statement with a correct body and with the following header for ( i = 20; i >= 2; i += 2 ) a) a syntax error b) a divide-by-zero error c) an infinite loop d) the even values of i from +* down to +.

ANS: (c) 4.34. Which statement is generally false? a) Statements preceding a for and statements in the body of a for should typically be merged into the for header. b) Limit the size of control structure headers to a single line, if possible. c) Initialization of a for loop control variable can occur before the for loop executes and not in the loop itself. d) The increment portion of a for header can be a decrement. ANS: (a) 4.35. Which expression raises C to the < power a) C ** < b) C B < c) C po9 < d) po9 CF < ! ANS: (d) 4.36. Which statement is true? a) Use float variables to perform monetary calculations in C. b) Use double variables to perform monetary calculations C. c) Monetary calculations can be performed in C. d) Printing with ?.+f guarantees correct monetary calculations in C. ANS: (c) 4.37. Which statement is true? a) The conversion specifier ?K.+f prints a floating-point value with a field width of 10 positions. b) The conversion specifier ?K.+f prints a floating-point value with 7 positions to the left of the decimal point. c) The conversion specifier ?K.+f prints a floating-point value with 5 positions to the left of the decimal point. d) The conversion specifier ?K.+f prints a floating-point value with 4 positions to the left of the decimal point. ANS: (d) 0.8 T&+ (;%t$& M#2t%*2+-S+2+$t%!n St't+)+nt 4.38 A s9itch statement should be used

(a) as a single-selection structure (b) as a double-selection structure (c) when a variable may assume many different values which must be tested against (d) to replace all if and ifDelse statements ANS: (c)

4.39 In a switch statement (a) a &reaL is required after each case (b) multiple actions do not need to be enclosed in braces (c) a default case is required (d) a &reaL is required after the default case ANS: (b)

4.40. Which statement regarding the s9itch statement is false? a) It is appropriate for algorithms that contain a series of decisions in which a variable or expression is tested separately for each of the constant integral values it may assume. b) The default case is required. c) The default case must be at the bottom of the s9itch after all the nondefault cases. d) Many cases may all invoke the same code. ANS: (b) 4.41. Which statement is true? a) ENG must have the value 1 on all C systems. b) ENG is a symbolic constant defined in the <s<m&ol.h> header file. c) ENG is a symbolic variable defined in the <stdio.h> header file. d) ENG is a symbolic integer constant defined in the <stdio.h> header file. ANS: (d) 0.9 T&+ "!G;&%2+ R+*+t%t%!n St't+)+nt 4.42 If a do9hile statement is used, (a) an infinite loop will not take place (b) the counter must be preincremented if it is also the condition

(c) the body of the loop will execute at least once (d) an off-by-one error will not occur ANS: (c)

4.43 The following program segment will


int counter 6 ,; do I printf "?i F counter !; J 9hile 55counter <6 ,* ! ;

(a) print the numbers 1 through 11 (b) print the numbers 1 through 10 (c) print the numbers 1 through 9 (d) cause a syntax error ANS: (b)

4.44. Which statement is true? a) The do 9hile repetition statement is an alternate notation for the 9hile repetition statement; these statements function identically. b) The do 9hile repetition statement tests the loop-continuation condition before the loop body is performed. c) The loop body of a correct do 9hile repetition statement is always executed at least once. d) The braces delineating the body of a do 9hile statement are always required. ANS: (c) 0.: T&+ 6 +'B 'n" $!nt%n#+ St't+)+nt( 4.45 Which of the following is false? (a) &reaL and continue statements alter the flow of control. (b) continue statements skip the remaining statements in the body of the loop in which they are embedded. (c) &reaL statements exit from the loop in which they are embedded. (d) continue and &reaL statements may be embedded within all C++ structures. ANS: (d)

4.46. Which statement is true? a) The &reaL statement causes an immediate exit from a 9hile, for, do 9hile or if else statement. b) The continue statement is designed for use with the 9hile, for, do 9hile or s9itch statements. c) An equivalent 9hile statement for any for statement can always be formed. d) The &reaL statement causes an immediate exit from a 9hile, for, do 9hile or s9itch statement. ANS: (d) 0.1= L!.%$'2 O*+ 't! ( 4.47 In C, the condition - > < > , (a) evaluates correctly and should be replaced by ( - > < 77 < > , ) (b) does not evaluate correctly and should be replaced by ( - > < 77 < > ,) (c) evaluates correctly and should not be replaced by ( - > < 77 < > , ) (d) does not evaluate correctly and should not be replaced by ( - > < 77 < > ,) ANS: (b) 4.48 The OR (OO) operator (a) has higher precedence than the AND (77) operator (b) stops evaluation upon finding one condition to be true (c) associates from right to left (d) is a ternary operator ANS: (b)

4.49 The expression


if num %6 A/ ! < A/ !

can not be replaced by: (a) if num > A/ OO num (b) if % num 66 A/ ! (c) if num P A/! (d) if % num P A/! ANS: (d)

4.50 An operator that associates from right to left is (a) %6 (b) F (c) ! (d) H: ANS: (d) 4.51 An example of a unary operator is (a) a relational operator (b) an assignment operator (c) an increment operator (d) a logical operator ANS: (c)

4.52. Which statement is true? a) To test multiple conditions in the process of making a decision requires logical operators. b) The keywords for the logical operators are Q;R, NR and ;N2. c) The logical AND of two expressions is true if and only if each of the conditions is true. d) Truth tables deal only with cases in which all conditions are truthful (i.e., true). ANS: (c) 4.53. Which statement is true? a) Operator OO has a higher precedence than operator 77. b) In expressions involving operator OO, making the condition that is most likely to be false the leftmost condition can often reduce execution time. c) The logical negation operator is a binary operator. d) In expressions using operator 77, making the condition that is most likely to be false the leftmost condition can often reduce execution time. ANS: (d) 0.11 C!n3#(%n. EF#'2%t4 D==E 'n" A((%.n)+nt D=E O*+ 't! ( 4.54 Variables are also known as

(a) lvalues, but can be used as rvalues (b) lvalues, and can not be used as rvalues (c) rvalues, but can be used as lvalues (d) constant variables ANS: (a) 4.55 Consider the following code, assuming that C is an integer variable with an initial value of ,+:
if C 6 A ! printf "?iF C!;

What is the output? (a) 6 (b) 12 (c) nothing (d) a syntax error is produced ANS: (a) 4.56 Of the following, which is not a logic error? (a) omitting the space between the word case and the integral (alue being tested in a s9itch statement (b) dividing by zero (c) failing to initialize counter and total variables before the body of a loop (d) Using commas instead of the two required semicolons in a for header ANS: (d)

4.57. Which statement is false? a) Any expression in C that produces a value can be used in the decision portion of any control structure. b) When tested for truth or falsity, an expression that produces a nonzero value is treated as true. c) Assignments in C produce a value, namely the value that the left-hand side of the assignment had prior to the assignment. d) Operator 66 is for comparisons; operator 6 is for assignment. ANS: (c)

0.12 St #$t# +"-P !. '))%n. S#))' 4 4.58 The ____________, __________, and ____________ are the only three forms of control necessary. (a) s9itch, if, else (b) seSuence, selection, repetition (c) &reaL, continue, ifelse (d) for, 9hile, do9hile ANS: (b)

4.59. Which statement is true? a) Connecting flowchart symbols arbitrarily always forms structured programs. b) In a structured program, control structures can be only stacked or sequenced. c) In the Rules for Forming Structured Programs (and Structured Flowcharts), the rule that states, Any rectangle (action) can be replaced by any control structure is called the nesting rule. d) Any form of control ever needed in a C program can be expressed in terms of the 9hile, do 9hile and for statements. ANS: (c)

5.1 Int !"#$t%!n 5.2 P !. ') M!"#2+( %n C 5.1 All of the following are true of functions except: (a) they define specific tasks that can be used at many points in a program (b) a function call must specify the name and arguments of the function (c) the definition of a function is always visible to other functions (d) the implementation of a function is hidden from the caller ANS: (c)

5.2. Experience has shown that the best way to construct a program is from small pieces. This is called __________. a) bottom up b) the whole is greater than the sum of the parts c) divide and conquer d) recursion ANS: (c) 8.1. hich is not an ANS# standard librar& !unction a) printf b) main c) scanf d) po9 ANS: (b) 8.3. hich one item is most di!!erent !rom the other three" a) wor+er !unction b) caller c) calling !unction d) boss !unction ANS: (a) 8.8. hen a called !unction completes its tas+) it normall& a) terminates program execution normall&

b) aborts program execution c) logs its results d) returns to the calling !unction ANS: (d) 8.6. hich statement is true" a) %he boss !unction normall& +nows how the wor+er !unction per!orms its designated tas+s. b) A wor+er !unction ma& not call other wor+er !unctions. c) >?iding@ o! implementation details ma+es it di!!icult to understand so!tware. d) %he boss !unction is normall& unaware when a wor+er !unction calls a !unction. ANS: (d) 8.7. Aunctions are ---------- b& a !unction call. a) in(eigled b) in(o+ed c) internali4ed d) in(erted ANS: (b) 5.- M't& L%6 ' 4 F#n$t%!n( 5.8 All math library functions return the data type (a) lon> dou&le (b) int (c) float (d) dou&le ANS: (d)

5.9. All functions in the math library return the data type __________. a) float b) int c) lon> d) dou&le ANS: (d)

5.10. What happens when you do not include math.h when using functions in the math library? a) compilation error b) execution error c) logic error d) strange results may occur ANS: (d) 5.11. If a 6 K.*, & 6 K.* and c 6 A.*, then what is printed by printf( %.2f, sqrt( a + b * c ) ); a) -0 b) K.** c) K d) -0.** ANS: (b) 5.12. What is the value of fa&s a) / b) /.* c) (/ d) P/.* ANS: (b) 5.0 F#n$t%!n( 5.13 Which of the following is not included in <math.h>? (a) po9 (b) floor (c) ln (d) lo>,* ANS: (c) 5.14 A valid reason for building programs out of functions is (a) that the divide-and-conquer approach facilitates program construction (b) that pre-existing functions can be used to create new programs (c) the avoidance of code repetition within a program (d) all of the above
(/.* !?

ANS: (d)

5.15. Which is not a motivation for functionalizing a program? a) The divide-and-conquer approach makes program development more manageable. b) Software reusabilityusing existing building blocks to create new programs. c) Avoid repeating code. d) Execution performancefunctionalized programs run faster. ANS: (d) 5.16. Which statement is false? a) Each function should be limited to performing a single, well-defined task. b) If you cannot choose a concise name that expresses what a function does, it is possible that the function is attempting to perform too many diverse tasks. c) Every function should be broken into smaller functions. d) A functions parameters are local variables. ANS: (c) 5.5 F#n$t%!n D+3%n%t%!n( 5.17 The function prototype
dou&le m<3Srt int C !;

(a) defines a function called m<3Srt which takes an integer as an argument and returns a dou&le (b) defines a function called dou&le which calculates square roots (c) defines a function called m<3Srt which takes an argument of type C and returns a dou&le (d) defines a function called m<3Srt which takes a dou&le as an argument and returns an integer ANS: (a) 5.18 Using the following function definition, the parameter list is represented by
Q T $ ! I R J

(a) A (b) B (c) C (d) D ANS: (c) 5.19 Using the following function definition, the return value type is represented by
Q T $ ! I R J

(a) A (b) B (c) C (d) D ANS: (a) 5.20 Which of the following will not produce a syntax error? (a) omitting a return type from a function definition (b) returning a value from a function defined as void (c) defining a function parameter again inside a function (d) using the same names for arguments passed to a function and the corresponding parameters in the function definition ANS: (d) 5.21 Which of the following is not an indication that a function is too complex? (a) it has a large size (b) it has a large parameter list (c) its name is a clear reflection of its function (d) it performs multiple tasks ANS: (c) 5.22 Which of the following functions does not contain any errors? (a) 8oid printnum int C !
I print "?iF C !; return C; J

(b)
I

int cu&e

int s !

int s; return J

s * s * s !;

(c) (d)

dou&le triple float n ! return ) * n !; dou&le circumference int r !; return /.,- * + * r !;

ANS: (c)

5.23. int sSuare a) datatype b) stereotype c) prototype d) proceduretype ANS: (c)

int !;

is an example of a function __________.

5.24. As used in int square( int ); int is not a(n) __________. a) data type b) parameter type c) return type d) function prototype ANS: (d) 5.25. Which statement is true? a) Omitting the return value type in a function definition causes a syntax error if the function prototype specifies a return type other than dou&le. b) Forgetting to return a value from a function that is supposed to return a value is a compilation error. c) Returning a value from a function whose return type is 8oid is a syntax error. d) The return type for main must be omitted. ANS: (c) 5.26. The type of a parameter whose type is omitted in a function defeinition is __________. a) int b) dou&le

c) lon> d) float ANS: (a) 5.27. The most concise notation to use to define function parameters x and y as double is __________. a) CF < b) CF dou&le < c) dou&le CF < d) dou&le CF dou&le < ANS: (d) 5.28. Placing a semicolon after the right parenthesis enclosing the parameter list of a function definition is a __________ error. a) logic b) syntax c) fatal runtime d) nonfatal runtime ANS: (b) 5.29. Which statement is true? a) The type of every parameter in a function parameter list must be included. b) The type of every argument in a function call must be included. c) It is not incorrect to use the same names for the arguments passed to a function and the corresponding parameters in the function definition. d) Defining a function parameter again as a local variable within the function is a logic error. ANS: (c) 5.30. Which statement is false? a) Every block is a compound statement. b) Every compound statement is a block. c) Blocks can be nested. d) Compound statements can be nested. ANS: (b) 5.31. Which statement is true? a) Programs should be written as collections of small functions.

b) A function must be no longer than one page. c) The best engineered functions have many parameters and perform many distinct tasks. d) Every function must include an explicit return statement. ANS: (a) 5.6 F#n$t%!n P !t!t4*+( 5.32 A function prototype does not have to (a) include parameter names (b) terminate with a semicolon (c) agree with the function definition (d) match with all calls to the function ANS: (a) 5.33 A function prototype can always be omitted when: (a) a function is defined before it is first invoked (b) a function is invoked before it is first defined (c) a function takes no arguments (d) a function does not return a value ANS: (a)

5.34. Which statement is false? a) The compiler uses function prototypes to validate function calls. b) Prior to ANSI C, C did not include function prototypes. c) A function prototype tells the compiler the type of data returned by the function, the number of parameters the function expects to receive, the types of these parameters and the order in which parameters of these types are expected. d) The designers of ANSI C++ borrowed the notion of function prototypes from the developers of C. ANS: (d) 5.35. The forcing of arguments to the appropriate types is commonly called __________. a) conversion

b) casting c) coercion d) transmogrification ANS: (c) 5.8 H+'"+ F%2+( 5.36 Each standard library has a corresponding __________. (a) function (b) variable type (c) header file (d) cd-rom ANS: (c)

5.37. Which standard library header file contains function prototypes for conversions of numbers to text and text to numbers, memory allocation, random numbers and other utility functions. a) <stdar>.h> b) <stdli&.h> c) <stdutl.h> d) <stddef.h> ANS: (b) 5.9 C'22%n. F#n$t%!n(: C'22 64 V'2#+ 'n" C'22 64 R+3+ +n$+ 5.38 When arguments are passed by __________, the caller allows the called function to modify the original variables value. (a) value (b) reference (c) both a and b (d) none of these ANS: (c) 8.1,. hich statement is true" a) hen an argument is passed call b& re!erence) a cop& o! the argumentBs (alue is made and passed to the called !unction. b) ith call b& re!erence) changes to the passed (alue do not a!!ect the original (ariableBs (alue in the calling !unctions.

c) 0all b& (alue should be used whene(er the called !unction does not need to modi!& the (alue o! the callerBs original (alue. d) 0all b& (alue should onl& be used with trusted called !unctions that need to modi!& the original (ariable. ANS: (c) 5.: R'n"!) N#)6+ A+n+ 't%!n 5.40 The rand function generates a data value of the type (a) unsi>ned int (b) int (c) lon> int (d) short int ANS: (a) 5.41 A variable that can only have values in the range * to A//)/ is a (a) four-byte int (b) four-byte unsi>ned int (c) two-byte int (d) two-byte unsi>ned int ANS: (d) 5.42 In the expression
n 6 a 5 rand ! ? &;

(a) & is the shifting value (b) a is the scaling value (c) & is equal to the width of the desired range of integers (d) both (a) and (c) ANS: (d) 5.43 srand (a) should be called before each call to rand (b) should be used instead of rand to generate truly random numbers (c) is unnecessary in C (d) can use time as an automatically input seed value ANS: (d)

5.44. Which statement is false?

a) Function rand generates and integer between 0 and MQU. b) The range of values produced directly by rand is often different than what is needed in a specific application. c) The number A in the expression rand ? A is called a scaling factor. d) The rand function prototype is in <stdli&.h>. ANS: (a) 5.1= EC')*2+: A A')+ !3 C&'n$+ 5.11 St! '.+ C2'((+( 5.45 An identifiers storage class (a) determines the period during which that identifier exists in memory (b) determines whether an identifier is known only in the current source file or in any source file with proper definitions (c) determines where the identifier can be referenced in a program (d) all of the above ANS: (a) 5.46 A compiler can ignore the storage class specifier (a) auto (b) re>ister (c) static (d) eCtern ANS: (b) 5.47 Which of the following is not true of static local variables? (a) they are accessible outside of the function in which they are defined (b) they retain their values when the function is exited (c) they are initialized to zero if not explicitly initialized by the programmer (d) they can be pointers ANS: (a)

5.48. Which is not an attribute of a variable a) name b) definition

c) type d) value ANS: (b) 5.49. Which is not a storage class a) automatic b) re>ister c) eCtern d) static ANS: (a) 5.50. Which is not an attribute of a variable? a) storage class b) storage duration c) scope d) external class ANS: (d) 5.51. An identifiers __________ is where the identifier can be referenced in a program. a) locality b) vicinity c) neighborhood d) scope ANS: (d) 5.52. Global variables and function names are of storage class __________ by default. a) re>ister b) eCtern c) static d) auto ANS: (b) 5.12 S$!*+ R#2+( 5.53 Labels are the only identifiers with (a) function scope

(b) file scope (c) block scope (d) function-prototype scope ANS: (a)

5.54 The only identifiers that can be reused elsewhere in a program without any ambiguity are (a) global variables (b) static local variables (c) those in the parameter list of a function prototype (d) those in the parameter list of a function definition ANS: (c)

5.55. Which statement is false? a) When we define a local variable in a block it can be referenced only in that block or in blocks in which that block is nested. b) Labels are the only identifiers with function scope. c) Labels can be used anywhere in the function in which they appear, but can not be referenced outside the function body. d) Labels are used in s9itch statements and in >oto statements. ANS: (a) 5.56. Which is not a scope for an identifier? a) function scope b) record scope c) block scope d) function prototype scope ANS: (b) 5.1- R+$# (%!n 5.57 A recursive function is a function that (a) returns a dou&le (b) takes 3 arguments (c) calls itself (d) is inside of another function

ANS: (c) 5.58 What value does function mystery return when called with a value of 4?
int m<ster< int num&er ! I if num&er <6 , ! return ,; else return num&er * m<ster< J

num&er P , !;

(a) 1 (b) 24 (c) 0 (d) 4 ANS: (b)

5.59 Recursion is memory-intensive because (a) it must occur numerous times before it terminates (b) previous function calls are still open when the function calls itself and the arguments of these previous calls still occupy space on the call stack (c) many copies of the function code are created (d) it requires large data values ANS: (b) 8.6/. hich statement is !alse" a) A recursi(e !unction is a !unction that calls itsel! either directl& or indirectl& through another !unction. b) A recursi(e !unction +nows how to sol(e onl& one or more base cases. c) %he recursion step executes a!ter the original call to the !unction terminates. d) #n order !or the recursion to e(entuall& terminate) each time the !unction calls itsel! with a slightl& simpler (ersion o! the original problem) this se$uence o! smaller and smaller problems must e(entuall& con(erge on a base case. ANS: (c)

5.10 EC')*2+ U(%n. R+$# (%!n: T&+ F%6!n'$$% S+ %+( 5.61 Assuming the following pseudocode for the fibonacci series, what is the value of the 5th fibinacci number?
fibbonacci( 0 ) = 0 fibonacci( 1 ) = 1 fibonacci( n ) = fibonacci( n 1 ) + fibonacci( n 2 ) (a) 0 (b) 1 (c) 3 (d) 5 ANS: (c)

8.62. hich statement is !alse" a) %he ANS# 0 standard does not speci!& the order in which the operands o! most operators are to be e(aluated. b) %he ANS# 0 standard speci!ies the order o! e(aluation o! operators 77) OO) comma) and H:. c) A program that e(aluates Aibonacci numbers recursi(el& achie(es high per!ormance because o! exponential complexit&. d) <rograms that depend on the order o! e(aluation o! the operands o! operators other than 77) OO) comma) and H: can !unction di!!erentl& on s&stems with di!!erent compilers.
ANS: (c)

5.15 R+$# (%!n 1(. It+ 't%!n 5.63 Recursion is to the base case as iteration is to what? (a) the counter (b) a repetition structure (c) failure of the loop continuation test (d) a selection structure ANS: (c) 5.64 All of the following are reasons to use recursion except: (a) an iterative solution is not apparent (b) the resulting program is easier to debug (c) it more naturally mirrors the problem

(d) it maximizes software performance ANS: (d) 8.68. hich statement is !alse" a) Coth recursion and iteration are based on a control structure. b) Coth iteration and recursion in(ol(e repetition. c) #teration with sentinel7controlled repetition and recursion each graduall& approach termination. d) Coth iteration and recursion can occur in!initel&. ANS: (c)

6.1 Int !"#$t%!n 6.1. Arrays are data structures consisting of related data items of the same __________. a) sort order b) subscript c) type d) element ANS: (c) 6.2. Arrays and structures are __________ entities in that they remain the same size throughout program execution. a) dynamic b) automatic c) register d) static ANS: (d) 6.3. Lists, queues, stacks and trees are __________ data structures that may grow and shrink as programs execute. a) flexible b) automatic c) dynamic d) static ANS: (c) 6.2 A '4( 6.4 An array is not (a) a consecutive group of memory locations (b) subscripted by integers (c) pointer-based (d) a dynamic entity ANS: (d)

6.5 Assuming that int a has a value of ) and that integer array & has K elements, what is the correct way to assign the value of the sum of ) and the third element, to the fifth element of the array? (a) &V a 5 , W 6 &V a W 5 ); (b) &V a 5 , W 6 &V a ( , W 5 ); (c) &V a W 5 , 6 &V a 5 )W; (d) &V a 5 + W 6 &V a W 5 ); ANS: (b) 6.6 Which of the following is not true? (a) the first element of an array is the zeroth (b) the last element of an array is the array size - 1 (c) the position number contained within square brackets is called a subscript (d) a subscript cannot be an expression. ANS: (d)

6.7. An array is a group of memory locations related by the fact that they all have __________ name and __________ type. a) different, different b) same, different c) different same d) same, same ANS: (d) 6.8. The first element in every array is the __________ element. a) null b) , c) * d) empty ANS: (c) 6.9. Which statement is false? a) The brackets used to enclose the subscript of an array are not an operator in C. b) To refer to a particular element in an array, we specify the name of the array and the position number of the element in the array. c) The position number within an array is more formally called a

subscript. d) Array element seven and the seventh element of an array do not mean the same thing. This is a frequent source of off-by-one errors. ANS: (a) 6.- D+3%n%n. A '4( 6.10 Which statement would be used to define a 10 element integer array c? (a) Qrra< c 6 intV ,* W; (b) c 6 intV ,* W; (c) int Qrra< cV ,* W; (d) int cV ,* W; ANS: (d)

6.11. Which definition tells the computer to reserve 12 elements for integer array c? a) cV ,+ W int; b) int c V ,, W; c) cV ,, W int; d) int cV ,+ W; ANS: (d) 6.6.0 EC')*2+( U(%n. A '4( 6.12 Which of the following is not a correct way to initialize an array? (a) int nV / W 6 I *F KF *F )F .F + J; (b) int nVW 6 I *F KF *F )F .F + J; (c) int nV / W 6 I K J; (d) int nV / W 6 I AF AF A J; ANS: (a) 6.13 Constant variables (a) can be assigned values in executable statements (b) do not have to be initialized when they are defined (c) can be used to specify array sizes, thereby making programs more

scalable (d) can be used to specify array sizes, but this makes programs harder to understand ANS: (c) 6.14 Referencing elements outside the array bounds (a) can result in changes to the value of an unrelated variable (b) is impossible because C checks to make sure it does not happen (c) is a syntax error (d) enlarges the size of the array ANS: (a) 6.15 Strings can not (a) be initialized using string literals (b) end in a character other than the null character (c) be initialized with initializer lists (d) be treated as arrays of characters ANS: (b) 6.16 Assume strin>, is a character arra&. Which of the following operations does not produce a string" (a) strin>,VW 6 "test; (b) strin>,VW 6 I XtYF XeYF XsYF XtYF X\*Y J; (c) strin>,VW 6 I XtYF XeYF XsYF XtY J; (d) strin>,VW 6 " ; ANS: (c)

6.17. Suppose a program contains the code for (i = 1; i < = 10; i++) n[ i ] = 0; Which statement about this code is true? a) It contains an off-by-one error. b) It contains a syntax error. c) It is initializing the first 10 elements of an array. d) It is initializing successive elements of an array. ANS: (d) 6.18. Whats wrong with this code?

int[] = ( 1, 2, 3, 4, 5); a) The array size must be specified in the square brackets. b) The parentheses should be square brackets. c) The square brackets should be curly braces. d) The parentheses should be curly braces. ANS: (d) 6.19. If there are fewer initializers than elements in the array, the remaining elements are __________. a) deleted b) ignored c) initialized to empt< d) initialized to zero ANS: (d) 6.20. Which statement is true? a) Arrays are automatically initialized to zero. b) To initialize all array elements to zeros, the array definition must explicitly initialize each element to zero. c) Array elements can be initialized to zero by the array definition only at compile time. d) Definitions for automatic arrays initialize the arrays at execution time. ANS: (d) 6.21. The following array definition int n[ 5 ] = { 32, 27, 64, 18, 95, 14 }; a) is correct b) causes a syntax error because there are only five initializers and six array elements. c) causes a logic error because there are only five elements but there are six initializers. d) causes a syntax error because there are six initializers but only five array elements. ANS: (d) 6.22. Which statement is true? a) A symbolic constant is an identifier that is replaced with replacement text by the C preprocessor after the program is compiled. b) Using symbolic constants to specify array sizes makes programs run

faster. c) Preprocessor directives are not C statements. d) The #define preprocessor directive must end in a semicolon. ANS: (c) 6.23. Which statement is true? a) Assigning a value to a symbolic constant in an executable statement is a syntax error. b) A symbolic constant is a variable. c) Space is reserved for a symbolic constant as with variables that hold values at execution time. d) Only uppercase letters can be used for symbolic constant names. ANS: (a) 6.24. Which statement is true regarding the statement ++frequency[ responses[ answer ] ]; a) This statement increases the appropriate freSuenc< counter depending on the value of responsesV ans9er W. b) This statement increases the appropriate ans9er counter depending on the value of freSuenc<V responses W. c) This statement increases the appropriate responses counter depending on the value of freSuenc<V ans9er W. d) This statement produces a syntax error because subscripts cannot be nested. ANS: (a) 6.25. Which statement is false? a) C has no built-in bounds checking to prevent the computer from referring to an array element that does not exist. b) The programmer is responsible for implementing array bounds checking. c) Referring to an element outside the array bounds is a syntax error. d) Referring to an element outside the array bounds is a logic error. ANS: (d) 6.26. Which statement is false? a) The string termination character is called the null character. b) The string "strin> actually occupies 7 characters in memory. c) The character representation of the last character in memory of a string

is X\*Y. d) A character array representing a string should be defined as large as the actual number of characters in the string minus the terminating character; C automatically provides the space for the terminating character. ANS: (d) 6.27. The definition char string1[] = first; is equivalent to a) character strin>,VW 6 I XfYF XiYF XrYF XsYF XtYF X\*Y b) char strin>, 6 I XfYF XiYF XrYF XsYF XtYF X\*Y J; c) char strin>,VW 6 I XfYF XiYF XrYF XsYF XtY J; d) char strin>,VW 6 I XfYF XiYF XrYF XsYF XtYF X\*Y J; ANS: (d)

J;

6.28. Which statement is false? a) Function scanf reads characters into memory from the keyboard until the first input whitespace character is encountered. b) Function scanf can write beyond the boundary of the array into which input is being placed. c) Function printf does not care how large the array it is printing is. d) When using scanf, you must always precede with the 7 operator the name of each variable into which inputs are being placed. ANS: (d) 6.29. Which statement is false? a) A static local variable exists for the duration of the program. b) A static local variable is visible only in the control structure in which it is defined. c) A static local array is not created and destroyed each time the function is entered and exited, respectively. d) Arrays that are defined static are automatically initialized once at compile time. ANS: (b) 6.5 P'((%n. A '4( t! F#n$t%!n( 6.30 Unless otherwise specified, entire arrays are passed __________ and individual array elements are passed __________.

(a) call-by-value, call-by-reference (b) call-by-reference, call-by-value (c) call-by-value, call-by-value (d) call-by-reference, call-by-reference ANS: (b) 6.31 Which of the following is false about a function being passed an array? (a) it knows the size of the array it was passed (b) it is passed the address of the first element in the array (c) it is able to modify the values stored in the array (d) all of the above are true ANS: (a) 6.32 To prevent modification of array values in a function (a) the array must be defined static in the function (b) the array parameter can be preceded by the const qualifier (c) a copy of the array must be made inside the function (d) the array must be passed call-by-reference ANS: (b) 6.33. To pass an array to a function, specify a) the name of the array without any brackets. b) the name of the array preceded by an empty pair of brackets. c) the name of the array followed by a pair of brackets including the size of the array. d) the name of the array followed by a pair of brackets including a number one less than the size of the array. ANS: (a) 6.34. Which statement is false? a) C automatically passes arrays to functions using simulated call by reference. b) When C passes an array to a function, the called function normally can modify the element values in the callers original array. c) The name of an array is actually the address of the first element of the array. d) When an array is passed in a function call, the calling function knows precisely where in the called functions memory the passed array is.

ANS: (d) 6.35. The special conversion specifier for printing addresses is __________. a) ?a b) ?m c) ?p d) ?loc ANS: (c) 6.36. Which statement is true? a) Entire arrays are passed simulated call by reference and individual array elements are normally passed simulated call by reference. b) Entire arrays are passed simulated call by reference and individual array elements are normally passed call by value. c) Entire arrays are passed call by value and individual array elements are normally passed simulated call by reference. d) Entire arrays are passed call by value and individual array elements are normally passed call by value. ANS: (b) 6.6 S! t%n. A '4( 6.37 Which statement about bubble sort is true? (a) a maximum of n passes are needed to sort the array, where n is the number of elements (b) swapping values requires two assignments (c) performance is maximized (d) the algorithm is very simple compared to other sorting procedures ANS: (d)

6.38. Which statement about the bubble sort is false? a) It is easy to program. b) It is a high-performance sort. c) It compares only adjacent elements with one another. d) The bubble sort compares successive pairs of elements. ANS: (b)

6.39. A bubble sort of 1000 elements requires a maximum of __________ passes. a) 1001 b) 1000 c) 999 d) 998 ANS: (c) 6.8 C'(+ St#"4: C!)*#t%n. M+'n, M+"%'n 'n" M!"+ U(%n. A '4( 6.40 In order to calculate the __________ of an array of values, the array must be sorted. (a) median (b) mode (c) mean (d) (a), (b), and (c) ANS: (a)

6.41. The _____ is the average value of a set of data items. a) mean b) median c) mode d) matrix ANS: (a) 6.42. Calculating which of the following normally requires the data to be sorted first a) mean b) median c) mode d) total ANS: (b) 6.43. The __________ is the value that occurs most frequently in the data. a) mean b) median c) mode d) master

ANS: (c) 6.9 S+' $&%n. A '4( 6.44 The binary search technique (a) is better suited to small arrays (b) is better suited to unsorted arrays (c) can only be used on a sorted array (d) is slower than a linear search ANS: (c) 6.45 The maximum number of comparisons needed for the binary search of a 2000 element array is (a) 9 (b) 15 (c) 11 (d) 14 ANS: (c) 6.46. Which of these is generally thought of as a high-performance technique? a) bubble sort b) linear search c) binary search d) iteration ANS: (c) 6.47. Which of the following statements is false? a) The linear searching method works well for small arrays. b) The linear searching method works well for unsorted arrays. c) The binary search algorithm eliminates from consideration one half of the elements in a sorted array after each comparison. d) The binary search terminates only when the search key is equal to the middle element of a subarray. ANS: (d) 6.48. A sorted array of a million elements can be searched by a binary search in __________ or fewer comparisons.

a) 10 b) 20 c) 30 d) 999,999 ANS: (b) 6.: M#2t%*2+-S#6($ %*t+" A '4( 6.49 A double subscripted array element incorrectly referenced as aV < W is actuall& e(aluated as (a) aV C WV < W (b) aV < W (c) aV C W (d) aV * W ANS: (a) 6.50 Given the following definitions, what is the value of &V
int &V + WV + W 6 I I , JF I ) F - J J; CF

, WV * W?

(a) 0 (b) 1 (c) 3 (d) this isnt a valid definition ANS: (c) 6.51 Which of the following does not initialize all of its elements to 0? (a) int &V + WV + W;
&V * WV * W 6 &V * WV , W 6 &V , WV * W 6 &V , WV , W;

(b) (c)

int &V + WV + W 6 I * J; int &V + WV + W; for int i 6 *; i < +; i55 ! for int M 6 *; M < +; M55 ! &V i WV M W 6 *;

(d) all of the above initialize all of their elements to 0. ANS: (d)

6.52. Which statement is false about multiple-subscripted arrays? a) C supports multiple-subscripted arrays. b) A common use of multiple-subscripted arrays is to arrange data into tables consisting of rows and columns.

c) To identify a particular table element requires two subscripts. d) Each ANSI C system can support arrays with as many subscripts as the programmer chooses. ANS: (d) Each ANSI C system can support arrays with as many subscripts as the programmer chooses. 6.53. An array containing 3 columns and 4 rows is typically referred to as a __________. a) 12-element array b) 3-by-4 array c) 13-element array, because of the zero element d) 4-by-3 array ANS: (d) 4-by-3 array 6.54. Which of the following initializations is not performed by the definition int b[ 2 ][ 2 ] = { { 1 }, { 3, 4 } }; is false? a)&V * WV * W is set to , b) &V * WV , W is set to , c) &V , WV * W is set to ) d) &V , WV , W is set to ANS: (b) &V * WV , W is set to ,

You might also like