C++ Midterm 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Assuming that x is 3 and y is 2, after the statement x-=y executes, what will the values of x and y be

1,2

an uninitialized local 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

a) the value last stored in the memory location reserved for that variable

End-of-line comments that should be ignored by the compiler are denoted using: a) Two forward slashes b) three forward slashes c) a slash and a star d) a slash and two stars

a) two forward slashes

Which of the following will not increment c by 1? a) c+1; b)c++; c)++c; d) c+=1;

a)c+1

The ____ object enables a program to read data from the user. a) cout b) cin c) cread d) cget

b) cin

In an activity diagram for an algorithm, what does a solid circle surrounded by a hollow circle represent? a) initial state b) final state c)action state d) transition

b) final state

Which of the following is a double-selection statement? a) if b) if else c) do while d) switch

b) if else

Which of the following is not an arithmetic operate? a) + b) - c) = d) %

c) =

In what order would the following operators be evaluated? - , * , / , + , % Assume that if two operators have the same precedence, the one listed first will be evaluated first. a) -*/+% b) %*/-+ c) %+/*- d) */%-+

d) */%-+

Which of the following is a compilation error? a) neglecting to declare a local variable in a function before it is used. b) using a triple equals sign instead of a double equals sign in the condition of an if statement c) omitting the left and right parentheses for the condition of an if statement d) all of these

d) all of these

Which of the following statements initializes the unsigned int variable counter to 10? a) unsigned int counter = 10; b) unsigned int counter = {10}; c) unsigned int counter{10}; d) all of these

d) all of these

Which of the following does not cause a syntax error to be reported by the C++ compiler? a) mismatched {}'s b) missing / in a comment c) missing ; at the end of a statement d) extra blank lines

d) extra blank lines

Which of the following uses C++11's list initialization to initialize count to 0? a) int count = 0 b) int count[0]; c) int count (0); d) int count {0};

d) int count {0};

Using a while loop's counter control variable in a calculation after the loop ends often causes a common logic error called: a) fatal logic error b) a counter exception c) syntax error d) off-by-one error

d) off-by-one-error

What is the value of "result" after the following C++ statements execute? int a{4}; int b{12}; int c{37}; int d{51}; int result { d % a * c + a % b + a}

result = 51 % 4 * 37 + 4 % 12 + 4 = 3 * 37 + 4 % 12 + 4 = 111 + 4 % 12 + 4 = 111 + 4 + 4 = 115 + 4 = 119

Which of the following code segments prints a single line containing "hello there" with the words separated by a single space? a) std::cout << "hello" << "there\n"; b) std::cout << "hello" << endl; std::cout << " there"; c) std:: cout << "hel"; std:: cout << "lo "; std:: cout << " there\n"; d) std:: cout << "hel" << "lo "; std:: cout << "there" << endl;

d) std:: cout << "hel" << "lo "; std:: cout << "there" << endl;

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;

8

The assignment operator _____ assigns the value of the expression on its right to the variable on its left. a) == b) := c) = d) <=

=

The conditional operator '(?:)' is a) the only ternary operator in C++ b) a unary operator c) associates from left to right d) accepts two operands

a) the only ternary operator in C++

The escape sequence for a newline is: a) \n b) \t c) \r d) \a

\n

What will be the output after the following C++ statements have been executed? int a{4}; int b{12}; int c{37}; int d{51}; if (a < b) { cout << "a < b" << endl; } if (a > b) { cout << "a > b" << endl; } if (d <= c) { cout << d <= c" << endl; } if (c != d) { cout << "c != d" << endl;)

a < b c != d

Which of the following is not a valid C++ identifier? a) 4Height b) Height c) HeIgHt d) height4 e) _height

a) 4Height

What is the output of the following statements? std::cout << "Hello "; std::cout << "World"; a) Hello World b) World Hello c) Hello World d) World Hello

a) Hello World

The data type boo: a) can take values 'true' and 'false' b) can take on any expression as a value c) can take on values -1, 0, 1 d) can only be used in a selection statement

a) can take values 'true' and 'false'

Pseudocode normally does not include a) declarations b) input and output c) algorithms d) control structure

a) declarations

Which of the following statements does not overwrite a preexisting value stored in a memory location? a) int a; b) number = 12; c) y = y+12; d) width = length;

a) int a;

Which of the following is not true pseudocode? a) it is executed by the computer. b) it helps the programmer "think out" a program c) it includes declarations and all types of statements. d) all of these

a) it is executed by the computer

Which of the following operations has the highest precedence? a) postincrement b) multiplication c) addition d) assignment

a) postincrement

Which of the following statements would display the phrase C++ is fun? a) std:: cout << "C++ is fun?\n"; b) fprintf("C++ is fun?\n"); c) 900 format (11HC++ is fun?) d) system.out.pringln("C++ is fun?);

a) std:: cout << "C++ is fun?\n";

How many times will the following loop print "hello"? i = 1; while ( 1 <= 10) { cout << "hello"; }

an infinite number of times

Which of the following statements is false? a) C++ requires all variables to have a type b) C++ fundamental types are portable c) int's may be 64 bits on some machines d) C++ programmers frequently have to write different version of programs for different platforms

b) C++ fundamental types are portable

Assuming that x is equal to 4, which of the following statements will not result in y containing the value 5 after execution? a) y =5; b) y = x++; c) y = ++x; d) y = x+1;

b) y = x++;

If x initially contains the value 3, which of the following sets x to 7? a) x++4; b) x+=4; c) x=+4; d) x+4=x;

b)x+=4;

If grade has a value of 60, what will the following code display? if (grade >= 60) { cout << "Passed"; } a) Nothing b) 60 c) Passed d) cout << "Passed"

c) Passed

Which of the following encompasses the other three? a) sequence strucutre b) repetition structure c) control structure d) selection structure

c) control structure

Which of the following is a repetition structure? a) if b) if else c) do while d) switch

c) do while

Which operation does not take place in the following example? int x {21}; double y {6}; double z {14}; y = x / z; x = 5.5 * y; a) implicit conversion b) promotion c) explicit conversion d) truncation

c) explicit conversion

Which of the following is true? a) assigning a double value to an int does not lose any data b) for fundamental type variables, list initialization syntax prevents narrowing conversions that could result in data loss c) for fundamental type variables, list initialization syntax allows narrowing conversions that could result in data loss d) none of these

c) for fundamental type variables, list initialization syntax prevents narrowing conversions that could result in data loss

Which of the following statements about nested if...else statements is true? a) and if...else statement may not be nested in another if...else b) each if else statement must contain only a simple condition c) in an if body, an inner if else executes only of the outer if statement's condition is true d) the statement(s) in an inner if always execute(s) if its condition is true

c) in an if body, an inner if else executes only if the outer if statement's condition is true

A block: a) must contain exactly three statements b) cannot contain declarations c) is a compound statement d) is represented by placing a semicolon where a statement would normally be

c) is a compound statement

Having a loop within a loop is known as: a) recursion b) doubling up c) nesting d) stacking

c) nesting

The std:: endl stream manipulator: a) inputs a newline b) flushes the output buffer c) outputs a newline and flushes the output buffer d) terminates the program

c) outputs a newline and flushes the output buffer

Specifying the order in which statements are to be executed in a computer program is called: a) an algorithm b) transfer of control c) program control d) pseudocode

c) program control

What is wrong with the following while loop? while (sum <= 1000) { sum = sum-30; }

the loop will never end


संबंधित स्टडी सेट्स

Praxis 5622 Combined Sets 2: Classroom Management, Assessment, Diverse Learners, Special Education

View Set

SCM: Ch. 5 - Sourcing Materials and Services

View Set

Chapter 5 Adaptations to Anaerobic Training Programs

View Set