Quiz 7: Increment and Decrement Operators

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Walk through the following code fragment and write the exact output printed to standard output. Assume value is defined as an int variable and initialized with the value -1. switch(value) { case -1: --value; case 2: value++; case 4: ++value; case 5: value*=5; case 6: value++; default: --value; } printf("%d", value);

0

Walk through the following code fragment and write the exact output printed to standard output. Assume variables x and y are of type int and initialized to values 100 and 200, respectively. if (x>100&&y<=200) printf("%d", ++x+y++); else printf("%d", 2*x++- --y);

1

Walk through the following code fragment and write the exact output printed to standard output. Assume value is defined as an int variable and initialized with the value 3. switch(value) { case 3: value+=3; case 1: value++; case 5: --value; case 4: value+=4; } printf("%d", value);

10

Walk through the following code fragment and write the exact output printed to standard output: int x=5, y=6+x++; printf("%d", y);

11

Walk through the following code fragment and write the exact output printed to standard output. Assume variables x and y are defined as type int. x = 5; y = 6 + ++x; printf("%d", y);

12

Consider the following code fragment where variables x, y, and z are int variables initialized with the values 17, 15 and 0, respectively. Assume variables t and w are of type double. z = x--+ --y/4; y = x--%3+ ++z/4; w = 17/3+6.5; t = ++x/4.0+15%4-3.5; Write the comma-separated variable values in this order: x, y, z, t, and w. Write the values of double variables rounded to 2 fractional digits. For example, 10.0 is written as 10.00 while 10.012 is written as 10.01.

16,6,21,3.50,11.50

Walk through the following code fragment to determine the value printed to the standard output stream and then pick the correct choice from the multiple choices. Assume all variables are of type int with x and y initialized to values 5 and 2, respectively. w = ++x * ++y; printf("%d", w); Select one: - 15 - 10 - 12 - the value printed to standard output stream is unspecified - 18

18

Walk through the following code fragment and write the exact output printed to standard output. Assume all variables are int variables with x and y initialized with values 2 and 4, respectively. z = ++x*y; printf("%d,%d,%d", x, y, z);

3,4,12

Walk through the following code fragment and write the exact output printed to standard output. Assume all variables are int variables with x and y initialized with values 2 and 4, respectively. z = x++*y; printf("%d,%d,%d", x, y, z);

3,4,8

Walk through the following code fragment and write the exact output printed to standard output. Assume variable x is defined as type int and is initialized to value 1. if (x>0) switch (x) { case 1: x+=3; case 3: ++x; case 6: x++; case 8: x*=8; default: --x; } else x+=2; printf("%d",x);

47

Walk through the following code fragment and write the exact output printed to standard output. Assume all variables are int variables with i and j initialized with values 54 and 23, respectively. l = i++ - 10 || --j; printf("%d,%d,%d", ++i, ++j, ++k);

56,24,2

Consider the following code fragment where variables x, y, z, and w are int variables initialized with the values 5, 3, 0, and 0, respectively: y = x++-++z; z = 2*++y+3; w = x++-2*++y+ ++z; z = w++-++x; w++; What are the values of each of these variables after the last statement executes? Write the comma-separated variable values in this order: x, y, z, and w.

8,6,0,10

Suppose w, x, and y are variables defined as type int. Is the statement w = x++ - y; equivalent to the following pair of statements? x+=1; w = x - y; True or false?

False

Suppose w, x, and y are variables defined as type int. Is the statement w = ++x - y; equivalent to the following pair of statements? x = x + 1; w = x - y; True or false?

True

Consider the following statement: b=2+++a; There are two parts to this question: Determine the individual tokens in the above statement. Will the compiler consider this source line to be valid? If the source line is valid C code, write y; otherwise write n. Write your answers (only) in this format: the comma-separated list of tokens followed by a comma followed by the character (y or n) indicating whether the source line is valid C code or not.

b,=,2,++,+,a,;,n

Walk through the following code fragment to determine the value printed to the standard output stream and then pick the correct choice from the multiple choices. Assume all variables are of type int with x and y initialized to values 5 and 2, respectively. w = ++x + (x * ++y); printf("%d", w); Select one: - 16 - the value printed to standard output stream is unspecified - 18 - 24 - 20

the value printed to standard output stream is unspecified

Walk through the following code fragment to determine the value printed to the standard output stream and then pick the correct choice from the multiple choices. Assume all variables are of type int with x and y initialized to values 5 and 2, respectively. w = y*x + ++y; printf("%d", w); select one: - 17 - the value printed to standard output stream is unspecified - 14 - 18 - 13

the value printed to standard output stream is unspecified

Consider the following code fragment: int x=5, y=6, z; z=x+++ ++y; /* determine the number of tokens*/ printf("%d",z); There are three parts to this questions: Determine the tokens in the 2nd line of the code fragment. Will the compiler consider this source line to be valid? If the source line is valid C code, write y; otherwise write n. If you've determined that the 2nd source line is valid C code, then write the exact value printed to standard output. Write your answers in this format: comma-separated list of tokens followed by a comma followed by a character (y or n) indicating whether the source line is valid C code or not. Only if you typed y then continue with a comma followed by the value printed to standard output.

z,=,x,++,+,++,y,;,y,12


Set pelajaran terkait

EXAM 1 Fin 2303-300 PART 1-Study

View Set

B-29 / Supervision of Battery Systems

View Set

Mizzou American Government Horner exam 4

View Set

Advanced Operating Systems Miderm

View Set

AP 🌏 Ch. 38 A World Without Borders

View Set

Chapter 9 Introduction to Refrigerating

View Set

Molecular biology and human genetics exam 1

View Set

Abdominal Sonography - Liver Study Guide 2019

View Set

Chapter 36 Nursing Fundamental Course Point

View Set