COP1220

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is the ending value of z? int x = 5; int y = 12; double z; z = (double)(y / x); a.0.0 b.2.0 c.2.4 d.3.0

B

Which statement is incrementing the integer x, where y is also an integer? a.x = x - 1; b.x = x + 1; c.y = x + 1; d.y = x - 1;

B

Which generates a random integer in the range 13..19? a.rand() % 19 b.rand() % (19 - 13) c.(rand() % (19 - 13)) + 13 d.(rand() % (19 - 13 + 1)) + 13

D

Which identifier name shows good practice? a.m_v b.revPhyMgt c.cost_of_shipping_furniture_crates_by_sea d.sizeOfBox

D

Which is an example of a process? a. int b.y, 10 c 15 d. x + y

D

What are the possible values for ((rand() % 9) + -4)? a.-4...4 b.-9...9 c.0...4 d.0...9

A

What are the possible values for rand() % 6? a.0...5 b.0...6 c.0...7 d.1...6

A

What does the compiler do upon reaching this variable declaration?int x; a.Allocates a memory location for x b.Initializes x with the value -1 c.Converts variable x from a double to an integer d.Increments x's value by 1

A

What does this code output? printf("I "); printf("want pie.\n"); a.I want pie. b."I " "want pie." c.I want pie d.I want pie e.I wantpie

A

What is the ending value of x? x = 160 / 20 / 4; a.2 b.16 c.32 d.No value; runtime error

A

What is the ending value of y? int x; int y; x = 2; y = ((x + 1) / 5) + (x / 2) ; a.1 b.1.6 c.4.5 d.Error: Division not possible

A

What is the ending value of y? int x; int y; x = 6; y = (1 / 2) * (x + 5); a.0 b.3 c.5 d.6

A

Given only int variables a and b, which is a valid expression? a.4a + 3 b.a + ab c.a + -2 d.2 x 3

C

In an instruction like: z = x + y, the symbols x, y, and z are examples of _____. a.output b.visibles c.variables d.instructions

C

The world population is over 7 billion. Which declaration uses the fewest bits while guaranteeing that worldPopulation can be assigned the value 7 billion without error? a. int worldPopulation; b. long worldPopulation; c. long long worldPopulation; d. long long long worldPopulation;

C

What is myChar assigned with? char myChar; myChar = '\''; a.A backslash: \ b.A double-quote: " c.A single-quote: ' d.A backslash and double-quote: \"

C

What is read into string myString for input "One-hit wonder"? scanf("%s", myString); a.One b.One- c.One-hit d.One-hit wonder

C

What is the ending value of cost? int numApples = 3; double cost; cost = 1.2 * numApples; a. 3 b. 3.2 c. 3.6 d. 4

C

What is the ending value of x? int y = 6; x = (1 / 2) * y + 8; a.7 b.8 c.11 d.14

C

What is the ending value of z? x = 0; y = 3; z = pow(x + 2, y); a.0 b.4 c.8 d.Error: Cannot have an expression within a function call

C

What is the purpose of a variable? a.To assign values b.To perform calculations c.To hold a value d.To hold a constant value

C

What is y after executing the statements? x = 4; y = x + 1; x = 3; y = y * 2; a.6 b.8 c.10 d.12

C

Which XXX results in the output "I feed my 3 cats"? #include <stdio.h>int main(void) {int numCats = 3;char choreStatement[] = "feed";XXX} a.printf("I %c my %d cats", &choreStatement, &numCats); b.printf("I %c my %d cats", choreStatement, numCats); c.printf("I %s my %d cats", choreStatement, numCats); d.printf("I %s my %d cats", &choreStatement, &numCats);

C

Which data type can be used instead of int to avoid overflow for an integer containing the value 3,000,000,000,000? a.double b.long c.long long d.long int

C

Which expression is evaluated first? w = y + 2 + 3 * x + z; a.y + 2 b.2 + 3 c.3 * x d.x + z

C

Which expression is most appropriate for randomly choosing a day of the week? a.rand() % 1; b.rand() % 6; c.rand() % 7; d.rand() % 8;

C

Which is correct? a.int area = 3.2; b.500 = int distance; c.int changeAmt = -321; d.212 = length;

C

Which is likely not covered in style guidelines? a.Variable initiation b.Variable names c.Number of files created d.Spacing used in indentation

C

Which is not a valid identifier? a.firstName b.first_name c.1stName d.name1

C

Which is not true? a.A variable declaration requires a name and memory location b.The compiler designates a new memory location for a variable the first time a value is assigned c.Variables must be declared before being assigned a value or read d.Every time a new value is assigned to a variable, the compiler designates a new memory location

C

Which variable naming convention is used for distanceFromSun? a.snake case b.hill valley case c.lower camel case d.varied capitalization case

C

myString is declared as a string and is the only variable declared. Which is a valid assignment? a.myString[] = 'Hello'; b.myString = ["Hey"]; c.myString[] = "H"; d.myString = [Hoy];

C

Which declaration assigns a variable with 5 such that the value can not be later changed? a. const int = 5; b. int numItems = 5; c. int NUM_ITEMS = 5; d. const int NUM_ITEMS = 5;

D

A sequence of instructions that solves a problem is called a(n) _____ . a.instruction b.process c.algorithm d.variable

C

Given char x and char z, which assigns x with the character value held in z? a.x = 'z'; b.x = "z"; c.x = z; d.'x' = 'z';

C

A double variable stores a value in 64 bits, using some bits for mantissa, some for exponent, and one for sign. Which is true about a double variable? a. Limited bits may cause some rounding of the mantissa. b. If a value is too large for a double, a float should be used instead. c. If a value is too large for a double, a long should be used instead. d. The compiler may sometimes use 63 bits for the mantissa.

A

Given char x, which reads an input character into x? a. scanf("%c", &x); b. scanf("%s", x); c. scanf("%s", &x); d. scanf("%c", x);

A

Given function Multiply(u, v) that returns u * v, and Add(u, v) that returns u + v, which expression corresponds to: Add(Multiply(x, Add(y, z)), w) a.(x * (y + z)) + w b.(x + (y + z) * w) c.((x * y) + z) + w d.(x * (y + z) * w)

A

If a program compiles without errors, the program is free from _____. a.syntax errors b.logic errors c.runtime errors d.semantic errors

A

What possible values can x % 10 evaluate to? (x is an integer). a.0..9 b.1..10 c.0..10 d.1..11

A

myChar is a character variable and is the only declared variable. Which assignment is valid? a.myChar = 't'; b.myChar = "t"; c.myChar = t; d.myChar = 'tx';

A

A program should compute two times x. Which statement has a logic error? a. y = x + x; b. y = 2 * x; c. y = x * x; d. y = x * 2;

C

An identifier can _____ . a.be a reserved word b.start with an underscore c.contain a period d.contain spaces

B

Choose the statement(s) that generate(s) this output: I wish you were here a.printf("I wish", "you were here"); b.printf("I wish\n"); printf("you were here"); c.printf("I wish"); printf("you were here\n"); d.printf("I wish", \n, "you were here");

B

For an integer constant x, which statement will yield a compiler error? a.w = x + 1; b.x = y + 1; c.y = x; d.z = x + x;

B

Given a list of syntax errors from a compiler, a programmer should focus attention on which error(s), before recompiling? a.All the errors b.The first error only c.The middle error only d.The last error only

B

The programmer expected myString to contain the phrase "Girls and Boys" but instead only holds "Girls". Why? User input: Girls and Boys char myString[12]; scanf("%s", myString); a.myString must be preceded by an ampersand (&) b.scanf stops reading a string at the first whitespace c.The variable myString was improperly declared d.The "%s" parameter should be "%ws"

B

What is the ending value of w? int w; int y; y = 34; w = y % 5; a.1 b.4 c.6 d.7

B

What is the ending value of y? sqrt(u) returns the square root of u. pow(u, v) returns u raised to the power of v. x = 9.0; y = 4.0; y = pow(sqrt(x), sqrt(y)); a. 8.0 b. 9.0 c. 6561.0 d. Error: The sqrt functions cannot appear in the call to the pow function

B

What is the output? #include <stdio.h> int main(void) { double dividend = 0.0; double divisor = 0.0; printf("%lf\n", dividend / divisor); dividend = 3.0; printf("%lf\n", dividend / divisor); return 0; } a.inf nan b.nan inf c.inf 0.0 d.nan 0.0

B

What is the value of x? int y = 9; int z = 3; double x; x = (y / (z + 1.0)); a.2 b.2.25 c.3 d.Error: The operands are different types and cannot be divided

B

Which expression doubles x? a.x += 2; b.x *= 2; c.x *= x; d.x *= x * 2;

B

Which expression evaluates to 3.5? int x = 7; int y = 1; a .x * (1 / 2) b. (x / 2.0) c. x.0 / 2 d. (x / 2) * 1.0

B

Which expression fails to compute the area of a triangle having base b and height h (area is one-half base time height)? a. (1.0 / 2.0 ) * b * h b. (1 / 2) * b * h c. (b * h) / 2.0 d. 0.5 * b * h

B

Which is a valid compound operator? a. $= b. %= c. != d. ?=

B

Which is best declared as a constant? a. The number of people in a car b. The number of feet in a yard c. The number of leaves on a tree d. The number of insects in a room

B

Which prints a percent sign? a.printf("\%"); b.printf("%%"); c.printf("%"); d.printf('%');

B

Which statement causes overflow? int x = 3000; int y = 1000; int z; a. z = x * y; b .z = x * y * y; c. z = (x * x) + (y * y); d. z = (x * y) + (x * y) + (x * y);

B

A character variable's value is stored in memory as _____ . a.a graphical symbol b.a string c.a floating-point value d.an integer value

D

Dice have 6 sides, with values 1, 2, 3, 4, 5, and 6. Which expression randomly rolls one dice, directly yielding one of those values? a. (rand() % 5) b. (rand() % 5) + 1 c. (rand() % 6) d. (rand() % 6) + 1

D

For which quantity is a double the best type? a.People in a household b.Boxes on a conveyor belt c.Planes above a city d.Height of a building

D

What is output? #include <stdio.h> int main() { float newSize = 1.0; int i; for (i = 100; i < 120; ++i) { newSize *= i; } printf("%f", newSize); return 0; } a.1.000000 b.120.000000 c.4253829132348564723899756263864532992.000000 d.infinity

D

What is the ending value of y? pow(u, v) returns u raised to the power of v. x = 2.0; y = 3.0; y = pow(pow(x, y)) + 1.0; a.8.0 b.9.0 c.65.0 d.Error: The compiler complains about calling a function within another function

D

What is the purpose of style guidelines? a.To simplify compiling code from different programmers b.To enforce use of spaces over tabs for indentation c.To minimize syntax errors d.To improve consistency and readability

D

What is y after executing the statements? x = 5; y = x + 1; y = y * 2; a.5 b.6 c.8 d.12

D

What will a compiler do for the following code? /* numItems = 2; /* Total items to buy */rate = 0.5; */ a.Ignore numItems = 2, but generate code for rate = 0.5. b.Generate code for numItems = 2, but ignore rate = 0.5. c.Ignore both statements. d.Generate an error.

D

What will a compiler do for the following three lines of code?// x = 2; // width// y = 0.5// z = x * y; Total area a.Yield an error for line 1 (x = ...) b.Yield an error for line 2 (y = ...) c.Yield an error for line 3 (z = ...) d.Ignore all three lines

D

Which assignments would yield a non-floating-point number for y? y = 32.0 + (x / (z + 1.0)); a.x = 0.0; z = 1.0; b.x = -32.0; z = 1.0; c.x = 0.0; z = 0.0; d.x = 1.0; z = -1.0;

D

Which changes the value of m, where m = x * y + z / -8 % 9 + w? a.m = x * y + ((z / -8) % 9) + w b.m = x * y + (z / -8 % 9) + w c.m = ((x * y) + (z / -8) % 9) + w d.m = (x * y) + z / (-8 % 9 + w)

D

Which is correct? a.int main(void) { pkgHeight;pkgLength; pkgWidth; pkgVol = pkgHeight * pkgLength * pkgWidth; } b.int main(void) { int pkgHeight = 2; int pkgLength = 3; int pkgWidth = 5; pkgVol = pkgHeight * pkgLength * pkgWidth; } c.int main(void) { pkgHeight = 2; pkgLength = 3; pkgWidth = 5; pkgVol = pkgHeight * pkgLength * pkgWidth; } d.int main(void) { int pkgHeight; int pkgLength; int pkgWidth; int pkgVol;pkgVol = pkgHeight * pkgLength * pkgWidth;}

D

Which is true for comments? a.The compiler converts comments into a series of machine instructions. b.The compiler translates comments into ASCII values. c.The compiler allocates memory for comments along with for variables. d.The compiler does not generate machine code for comments.

D

Which is true? a.scanf() always truncates the input to avoid the string buffer from overflowing b.Character type variables do not require an ampersand (&) in scanf() c.A format specifier such as "%d" in scanf() is good practice but optional d.Format specifiers for scanf() and printf() are identical

D

Which statement, executed once at the start of main(), enables a program to generate a different sequence of pseudo-random numbers from rand() each time the program is run? a.srand(); b.srand(100); c.time(srand()); d.srand((int)time(0));

D

Why might style guidelines limit the number of characters per line? a.To speed up the code's execution b.To limit the size of the executable file c.To force use of short variable names d.To make the code more readable

D

int x is 1000000 and int y is 2000000. Outputting x * y will result in overflow. What is likely to appear at the output? a.The error message "overflow" b.The integer value -1 c.A floating-point value d.A seemingly arbitrary integer

D


Kaugnay na mga set ng pag-aaral

Ch 36 Management of Patients with Immune Deficiency Disorders

View Set

Accounting 100 Adaptive Practice Chapter 1

View Set

Combo with "NBDE Part II - 2006 Exam C" and 11 others

View Set

Business Communication final exam

View Set

Anatomy: Movements of Synovial Joints (Ch. 9)

View Set

AP Italiano- Governo-READING FACTS and FACTS PAGINE 5 & 6 del packet(da SC3-p 250-252 ed altro)-la costituzione e il governo italiano-2024

View Set