CS 1325 Chapter 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

/*

2.1 Lines beginning with the _______________ let the computer know that the rest of the line is a comment

a) message b) character string c) character d) literal ANS: (c)

2.10. Which of the following is not a synonym for a C string?

c) statement

2.11. The following line is most properly an example of a __________. printf( "Welcome to C!" );

b) \\

2.12. In a printf, a backslash is printed by enclosing in quotes

d) executable

2.13. A linked program is often called a(n) __________.

\t

2.14. The escape sequence for horizontal tab is __________.

1.1

2.15 Which of the following is not a valid integer value?

(a) _Test (b) TEST (c) 5test (d) test1 ANS: (c)

2.16 Which of the following is an invalid identifier (variable name)?

(a) printf("hi"); (b) print "hi"; (c) printf "hi"; (d) none of the above ANS: (a)

2.17 Which statement prints "hi" on the screen?

(a) +, assignment (b) =, assignment (c) *, stream manipulator (d) &, stream insertion ANS: (b)

2.18 The __________ sign is also known as the __________ operator

c) variable

2.19. A(n) __________ is a location in the computer's memory where a value can be stored for use by a program.

A "main" function

2.2 Which of the following must every C++ program have?

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.20. Which statement is false

a) a_valid_identifier b) a1_valid_identifier c) a_valid_identifier_ d) 1_valid_identifier ANS: (d)

2.21. Which of these is not a valid identifier?

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.22. Which of the following statements is false?

a) multiple_word_variable_name b) multipleWordVariableName c) multiplewordvariablename d) aReallyReallyLongMultipleWordVa ANS: (c)

2.23. Which of the following multiple word variable names does not conform to the good programming practices in the text?

a) sin tax b) syntax c) linkage d) execution ANS: (b)

2.24. A(n) __________ error is caused when the compiler can not recognize a statement.

a) && b) % c) @ d) & ANS: (d)

2.25. The address operator is

a) in the statement sum = integer1 + integer2; both = and + 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.26. Which statement is false?

a) Each variable being input in a scanf statement is generally preceded by an &. b) Each variable being output in a printf statement is generally not preceded by an &. 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.27. Which of the following is false?

(a) locations in the computer's memory (b) operators (c) integers (d) data types ANS: (a)

2.28 Variable names actually correspond to __________.

(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: (a)

2.28 When a number gets assigned to a variable that already has a value __________.

semicolon (;)

2.3 Every statement in C must end with a

a) name b) value c) alias d) type ANS: (c)

2.30. Every variable has all the attributes below, except

a) Reading a value into a memory location destroys the previous value. b) Reading a value out of a memory location destroys that value. c) sum = integer1 + integer2; involves destructive read-in. d) The statement in part c) also involves nondestructive read-out. ANS: (b)

2.31. Which of the following is false?

(a) 15 / 6 (b) 15 % 6 (c) 15 ^ 6 (d) 15 * 6 ANS: (b)

2.32 Which operation will find the remainder when 15 is divided by 6?

(a) 20 (b) 26 (c) 12 (d) 32 ANS: (a)

2.33 Evaluate the expression 3 * 4 % 6 + 4 *5

a) In algebra, we write ab to multiply a times b. b) In C, we write ab to multiple a times b. c) In C, the modulus operator is %. d) In C, integer division yields an integer result. ANS: (b)

2.34. Which statement is false?

a) 6 / 3 yields 2 b) 5 / 2 yields 2.5 c) 7 % 3 yields 1 d) 6 % 3 yields 0 ANS: (b)

2.35. Which statement about C arithmetic is false?

a) ab + ac b) (a * b ) + c c) a * b + c d) a * b + a * c ANS: (d)

2.36. a * (b + c) may also be written in C as

a) Parentheses may be used to force the order of evaluation to occur in any sequence desired by the programmer. b) Nested, or embedded parentheses are evaluated last. c) Multiplication has a higher precedence than addition. d) Subtraction has a lower precedence than division. ANS: (b)

2.37. Which statement about precedence is false?

a) The expression a * (b + c) + c * (d + e) contains nested parentheses. b) The expression y = a * x * x + b * x + c is a second degree polynomial. c) The C standard library provides function power to perform exponentiation. d) When we say evaluation of an expression proceeds from left to right we are referring to the additivity of the operators. ANS: (b)

2.38. Which expression is true?

(a) condition, true (b) condition, false (c) equality operator, true (d) relational operator, true ANS: (a)

2.39 C's if statement executes the statement inside its body if a specified __________ is __________.

\~

2.4 Which of the following is not a valid escape sequence?

(a) == (b) = (c) > (d) >= ANS: (a)

2.40 Which of the following is an equality operator?

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.41. 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.42. 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.43. 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 (=) is not an operator. d) A correct place to break a line is after a comma in a comma-separated list. ANS: (c)

2.44. Which statement is false?

a) int b) return c) if d) main ANS: (d)

2.45. Which of the following is not a keyword?

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.46. Which statement is false?

a) entered in a source file b) preprocessed c) compiled d) executed ANS: (d)

2.47. The order in which statements are __________ is called flow of control.

a) register b) volatile c) external d) struct ANS: (c)

2.48. Which is not a keyword?

Lengthy comments can cause poor execution-time performance.

2.5. Which statement about comments is false?

at preprocessor time

2.6. Lines beginning with a # are processed

a) It is required. b) This header file contains information and declarations used by the compiler when compiling standard input/output library functions such as printf. c) This header file contains information that helps the compiler determine if calls to library functions have been made correctly. d) This header helps locate bugs in your program at compile time, rather than at execution time (when errors are usually more costly to correct. ANS: (a)

2.7. Which of the following statements about the inclusion of <stdio.h> is false?

a) module b) statement c) method d) function ANS: (d)

2.8. In the line int main() the parentheses indicate that main is a program building block called a

a) function b) block c) statement d) header ANS: (b)

2.9. The pair of braces that delineate the body of main and the portion of the program between these braces is called a __________.

*a) Prints Passed b) Prints "Passed" : "Failed" c) Prints Failed d) Error

Q1: What happens with this code if grade is equal to 60? printf( "%s\n", grade >= 60 ? "Passed" : "Failed" );

a) 1023 b) 1024 c) 2047 *d) 2048

Q2: Consider the following code: p = 2; while ( p < 2000 ) p = 2 * p; What is the value of p after this while loop completes its execution?

a) EOF must have the value 1 on all C systems. b) EOF is a symbolic constant defined in the <symbol.h> header file. c) EOF is a symbolic variable defined in the <stdio.h> header file. *d) EOF is a symbolic integer constant defined in the <stdio.h> header file.

Q5:Which statement is true?

a) num > 65 || num < 65 b) !( num == 65 ) c) num - 65 *d) !( num - 65

Q6: The condition num != 65 cannot be replaced by:

a) Prints 0,1,2,3 *b) Prints 0,1,2,2, ... forever c) Prints 0,1,2 d) None of these

Q7: What does this code do? #include <stdio.h>#include <stdio.h> int main() { int i = 0; while (i < 3) { printf("%d,",i); if (i == 2) continue; i++; } printf("%d", i); }

*a) Prints 0,1,2,3 b) Prints 0,1,2,2, ... forever c) Prints 0,1,2 d) None of these

Q8: What does this code do? #include <stdio.h> int main() { int i; for (i = 0; i < 3; i++) { printf("%d,",i); if (i == 2) continue; } printf("%d", i); }

a) Prints HelloHiBye b) Prints Hello c) Error *d) Prints HelloHi

• Q4: What happens with this code? int main(void) { int num = 1; switch (num) { case 1: printf("Hello"); case 2: printf("Hi"); break; case 3: printf("Bye"); break; } return 0; }

a) > b) >= c) < *d) <=

•Q3: 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?


Conjuntos de estudio relacionados

Chapter 28. Hematologic and Lymphatic Disorders

View Set

Урок 1. Текст 1. Глагольно-именные словосочетания

View Set

A1-M7-Emphasis-of-Matter, Other-Matter, and Explanatory Paragraphs

View Set

Physics Chapters 12- 2 homeworks from here

View Set

Mod C - Cybersecurity Threats, Vulnerabilities, and Attacks

View Set

Pharmacology - PrepU Chapter :Antibiotics #1

View Set

Cybersecurity Course 1 Module 2 Questions

View Set

Chapter 44: Assessment of Digestive and Gastrointestinal Function

View Set

Ch 6: Cell Function / Ch 7: Cell Growth & Development

View Set