CPSC 1010 Final Review (Part 1)

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

Assume you have three int variables: x = 2, y = 6, and z. Choose the value of z in the following expression: z = (y / x > 0) ? x : y;. 6 4 3 2

2

Suppose sum, num, and j are int variables, and the input is 4 7 12 9 -1. What is the output of the following code? scanf("%d",sum); scanf("%d",num); for (j = 1; j <= 3; j++) { scanf("%d",num); sum = sum + num; } printf("%d\n",sum); 24 41 25 42

24

What is the output of the following C code? count = 1; num = 25; while (count < 25) { num = num - 1; count++; } printf("%d %d\n",count, num); 25 0 25 1 24 0 24 1

25 1

The control statements in the for loop include the initial statement, loop condition, and update statement. True False

True

The value of the expression 17 % 7 is ____. 4 2 1 3

3

The value of the expression 33/10, assuming both values are int data types, is ____. 0.3 3.0 3.3 3

3

Consider the following statement: int alpha[25][10];. Which of the following statements about alpha is true? Rows of alpha are numbered 1...25 and columns are numbered 1...10. Rows of alpha are numbered 0...24 and columns are numbered 1...10. Rows of alpha are numbered 0...24 and columns are numbered 0...9. Rows of alpha are numbered 1...24 and columns are numbered 0...9.

Rows of alpha are numbered 0...24 and columns are numbered 0...9.

What is the output of the following loop? count = 5; printf("St"); while (count <= 5) { printf("o"); count--; } This is an infinite loop. Sto Stop St

This is an infinite loop.

A control structure alters the normal sequential flow of execution in a program. True False

True

Assume all variables are properly declared. The output of the following C code is 2 3 4 5. n = 1; while (n < 5) { n++; printf("%d",n); } True False

True

C has only 5 built-in mathematical operators. True False

True

In C, the operators != and == have the same order of precedence. True False

True

A step-by-step problem-solving process in which a solution is arrived at in a finite amount of time is called a(n) ____. design algorithm linker analysis

algorithm

Suppose that alpha and beta are int variables and alpha = 5 and beta = 10. After the statement alpha *= beta; executes, ____. alpha = 5 alpha = 50.0 alpha = 10 alpha = 50

alpha = 50

Suppose that alpha and beta are int variables and alpha = 5 and beta = 10. After the statement alpha *= beta; executes, ____. alpha = 5 alpha = 10 alpha = 50.0 alpha = 50

alpha = 50

Suppose that alpha and beta are int variables. The statement alpha -= beta; is equivalent to the statement(s) ____. alpha = alpha - beta; alpha = beta - 1; alpha = 1 - beta; alpha = beta; beta = beta - 1;

alpha = alpha - beta;

What is the output of the following C code? int x = 35; int y = 45; int z; if (x > y) z = x + y; else z = y - x; printf("%d %d %d",x,y,z); 35 45 -10 35 45 0 35 45 10 35 45 80

35 45 10

Putting ____________________ in front of a logical expression reverses the value of that logical expression.

!

Consider the following statement: double alpha[10][5];. The number of components of alpha is ____. 15 50 150 100

50

The expression (int)(9.9) evaluates to ____. 10 9.0 9.9 9

9

Which of the following operators has the lowest precedence? || ! && =

=

____________________ can be used to identify the authors of the program, give the date when the program is written or modified, give a brief explanation of the program, and explain the meaning of key statements in a program.

Comments

In a sentinel-controlled while loop, the body of the loop continues to execute until the sentinel symbol is read. True False

False

In a two-dimensional array, the elements are arranged in a row-major order. True False

False

The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 100. True False

False

The operators !, &&, and || are called relational operators. True False

False

The statement int list[25]; declares list to be an array of 26 components, since the array index starts at 0. True False

False

Which of the following operators has the highest precedence? = ! * %

!

Which of the following is the "not equal to" relational operator? & ! | !=

!=

____ is a valid char value. "-129" 'A' 129 "A"

'A'

What is the output of the following C code? num = 10; while (num > 10) num = num - 2; cout << num << endl; 6 10 0 8

10

What is the output of the following code? int alpha[5] = {2, 4, 6, 8, 10}; int j; for (j = 4; j >= 0; j--) { printf("%d ",alpha[j]); } printf("\n"); 2 4 6 8 10 8 6 4 2 0 4 3 2 1 0 10 8 6 4 2

10 8 6 4 2

Which of the following expressions correctly determines that x is greater than 10 and less than 20? 10 < x || x < 20 10 < x && x < 20 (10 < x < 20) 10 < x < 20

10 < x && x < 20

Suppose sum and num are int variables, and the input is 18 25 61 6 -1. What is the output of the following code? sum = 0; scanf("%d",num); while (num != -1) { sum = sum + num; scanf("%d",num); } printf("%d\n",sum); 110 119 92 109

110

When you compile your program, the compiler identifies the logic errors and suggests how to correct them. True False

False

Choose the output of the following C statement: printf("Sunny\nDay "); Sunny \nDay Sunny Day Sunny \n Day Sunny \nDay endl

Sunny Day

Consider the following code. // Insertion Point 1 const float PI = 3.14; int main() { //Insertion Point 2 double r = 2.0; double area; area = PI * r * r; printf("Area = %lf",area); return 0; } // Insertion Point 3 In this code, where does the #include <stdio.h> statement belong? Anywhere in the program Insertion Point 3 Insertion Point 1 Insertion Point 2

Insertion Point 1

Consider the following code. // Insertion Point 1 const float PI = 3.14; int main() { double circumference = 0.0; //Insertion Point 2 double r = 2.0; double area; area = PI * r * r; // Insertion Point 3 printf("Area = %lf",area); return 0; } // Insertion Point 4 In this code, where does the statement circumference = 2.0 * PI * r; belong? Insertion Point 1 Insertion Point 2 Insertion Point 3 Anywhere in the program

Insertion Point 3

Suppose that alpha and beta are int variables. The statement alpha *= beta; is equivalent to the statement(s) ____. alpha = beta - 1; alpha = 1 - beta; beta = beta - 1; alpha = beta; alpha = alpha*beta;

alpha = alpha*beta;

The digit 0 or 1 is called a binary digit, or ____. Unicode hexcode bit bytecode

bit

The ____ statement can be used to terminate a loop. while break if switch

break

A sequence of eight bits is called a ____. double character binary digit byte

byte

Which of the following correctly declares name to be a character array and stores "William" in it? char name[6] = "William"; char name[8] = "William"; char name[8] = 'William'; char name[7] = "William";

char name[8] = "William";

A program called a(n) ____ translates instructions written in high-level languages into machine code. decoder compiler assembler linker

compiler

In a switch statement, if the value of the expression does not match any of the case values, the statements following the ____________________ label execute.

default

In row major order, the ____. first column is stored last first column is stored first first row is stored first first row is stored last

first row is stored first

Suppose that list is an array of 10 components of type int. Which of the following codes correctly outputs all the elements of list? for (int j = 0; j <= 9; j++) cout << list[j] << " "; cout << endl; for (int j = 1; j < 11; j++) cout << list[j] << " "; cout << endl; for (int j = 1; j <= 10; j++) cout << list[j] << " "; cout << endl; for (int j = 1; j < 10; j++) cout << list[j] << " "; cout << endl;

for (int j = 0; j <= 9; j++) cout << list[j] << " "; cout << endl;

Suppose that gamma is an array of 50 components of type int and j is an int variable. Which of the following for loops sets the index of gamma out of bounds? for (j = 0; j <= 48; j++) cout << gamma[j] << " "; for (j = 0; j <= 50; j++) cout << gamma[j] << " "; for (j = 0; j <= 49; j++) cout << gamma[j] << " "; for (j = 1; j < 50; j++) cout << gamma[j] << " ";

for (j = 0; j <= 50; j++) cout << gamma[j] << " ";

When a continue statement is executed in a ____, the update statement always executes. while loop do...while loop switch structure for loop

for loop

A loop that continues to execute endlessly is called a(n) ____ loop. infinite definite end unhinged

infinite

The declaration int a, b, c; is equivalent to which of the following? inta , b, c; int a; int b; int c; int abc; int a b c;

int a; int b; int c;

Consider the following declaration: int alpha[5] = {3, 5, 7, 9, 11};. Which of the following is equivalent to this statement? int alpha[5] = [3, 5, 7, 9, 11]; int alpha[] = (3, 5, 7, 9, 11); int alpha[] = {3, 5, 7, 9, 11}; int alpha[] = {3 5 7 9 11};

int alpha[] = {3, 5, 7, 9, 11};

You can use either a(n) ____ or a ____ to store the value of a logical expression. char, string int, bool float, double float, string

int, bool

What does <= mean? less than or equal to less than greater than greater than or equal to

less than or equal to

Consider the statement int list[10][8];. Which of the following about list is true? list has a total of 108 components. list has 10 rows and 8 columns. list has a total of 18 components. list has 8 rows and 10 columns

list has 10 rows and 8 columns

The devices that the computer uses to display results are called ____ devices. entry exit input output

output

Consider the following statements. int score; char grade[5]; if (score >= 65) strcpy(grade,"pass"); else strcpy(grade,"fail"); If score is equal to 75, the value of grade is "____________________".

pass

Which of the following is a legal identifier? program 1 program_1 program! 1program

program_1

Which of the following is a legal identifier? program 1 program! program_1 1program

program_1

Which of the following statements generates a random number from 0 to 49? srand(time(10)); num = rand()/50; srand(time(0)); num = rand() % 50; srand(time(0)); num = rand()50; srand(time(10)); num = rand() % 49;

srand(time(0)); num = rand() % 50;

Consider the following declaration: char str[15];. Which of the following statements stores "Blue Sky" into str? strcpy("Blue Sky"); str = "Blue Sky"; strcpy(str, "Blue Sky"); str[15] = "Blue Sky";

strcpy(str, "Blue Sky");

A(n) ____________________ is a sequence of zero or more characters.

string

Given the following declaration: int j; int sum; double sale[10][7]; which of the following correctly finds the sum of the elements of the fifth row of sale? sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[5][j]; sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[4][j]; sum = 0; for(j = 0; j < 10; j++) sum = sum + sale[5][j]; sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[4][j];

sum = 0; for(j = 0; j < 7; j++) sum = sum + sale[4][j];

A(n) ____________________ is a memory location whose contents can be changed.

variable


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

Philosophy Final Quiz (Potential)

View Set

Finance exam 4 (just the last two chapters)

View Set

BUS 351 Operations Management Ch.10 Quality Concepts

View Set

BIO221 Chapter 17 Adaptive Immunity

View Set

(1) Hormonal Regulation of the Menstrual Cycle

View Set

Chapter 13 APES Terms: The Urban Environment: Creating Sustainable Cities

View Set

MBF Connect - Chapter 9 Homework

View Set

OB: Chapter 16 Nursing Management During the Postpartum Period

View Set