Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. After this line of code executes what will be the value of “result”? int resu

ID: 3771878 • Letter: 1

Question

1. After this line of code executes what will be the value of “result”?   int result = 10 % 5;

2. After this line of code executes what will be the value of “result”?

            int result = 20 + 5 * 2 * 3 / 10 – 6 + 12 / 4;

3. What will be the value of “sumtotal” when this code is executed?
            int n1 = 3, n2 = 6, n3 = 2, sumtotal = 4;

            if (n1 ! = 4)

                        sumtotal -= n3;

            else if (n3 <= 5)

                        sumtotal = ++n2;

            else sumtotal += n1;

4. What is the final value of “y” after this for loop is finished?   for (y = 3; y<=14; y+=5)

5. What will the following C code print out?

            int x = 7, y = 5;

            if (x > 5)

                        if (y > 5)

                                    printf(“x and y are > 5”);

            else

                        printf(“x is <=5”);
            a) “x and y are > 5”

            b) “x is <=5”

            c) nothing will be printed

6. In which of the following is “y” not equal to 5 after execution? X is equal to 4.

            a) y = ++x;      b) y = x = 5;    c) y = 5;          d) y = x++;

Examine the following code and answer questions 7 below. IGNORE COMPILE ERRORS.
            int j = 0;
            for (j = 0; j <= 9; j++)
            {           printf( “%d”, 1 + ( rand() % 5 )); }
7. What are the POSSIBLE range of numbers that will be printed by the “printf()” statement above?

8. Examine the following code. What will be the output from the “printf()” statement below?

            #define S_SIZE 10

            char s[10] = { ‘g’ , ’o’ , ’m’ , ’i’ , ’z’ , ’z’ , ’o’ , ’u’ };

            int j = 0;

            for (j = S_SIZE -2; j > 4; j--) { printf( “%c”, s[j]);   }

Using the definitions below (IGNORE ALL COMPILE ERRORS):
            char s1 [ 50 ] = “JACK”, s2 [ 50 ]=”FRED”;
9.    What will this line of code print out >>> printf(“%c%s”, tolower( s1[ 1 ] ), &s2[ 1 ] );
            a) aRED          b) fRED           c) rRED           d) none of the above

10. What will this line of code print out >>> printf(“%c%s”, toupper( s2[ 1 ] ), &s1[ 1 ] );
            a) RFRED       b) RA c) RACK          d) none of the above

Explanation / Answer

1. After this line of code executes what will be the value of “result”?   
int result = 10 % 5;
Ans: 0

2. After this line of code executes what will be the value of “result”?
int result = 20 + 5 * 2 * 3 / 10 – 6 + 12 / 4;
Ans: 34

3. What will be the value of “sumtotal” when this code is executed?
int n1 = 3, n2 = 6, n3 = 2, sumtotal = 4;
if (n1 ! = 4)
sumtotal -= n3;
else if (n3 <= 5)
sumtotal = ++n2;
else sumtotal += n1;
          
Ans:2

4. What is the final value of “y” after this for loop is finished? for (y = 3; y<=14; y+=5)
Ans:13

5. What will the following C code print out?
int x = 7, y = 5;
if (x > 5)
if (y > 5)
printf(“x and y are > 5”);
else
printf(“x is <=5”);
a) “x and y are > 5”
b) “x is <=5”
c) nothing will be printed
Ans: x is <=5(b)

6. In which of the following is “y” not equal to 5 after execution? X is equal to 4.
a) y = ++x; b) y = x = 5; c) y = 5; d) y = x++;
Ans: d

Examine the following code and answer questions 7 below. IGNORE COMPILE ERRORS.
int j = 0;
for (j = 0; j <= 9; j++)
{ printf( “%d”, 1 + ( rand() % 5 )); }
7. What are the POSSIBLE range of numbers that will be printed by the “printf()” statement
above?
Ans: From 1 to 5(inclusive)

8. Examine the following code. What will be the output from the “printf()” statement below?
#define S_SIZE 10
char s[10] = { ‘g’ , ’o’ , ’m’ , ’i’ , ’z’ , ’z’ , ’o’ , ’u’ };
int j = 0;
for (j = S_SIZE -2; j > 4; j--) { printf( “%c”, s[j]); }
Ans : uoz

Using the definitions below (IGNORE ALL COMPILE ERRORS):
char s1 [ 50 ] = “JACK”, s2 [ 50 ]=”FRED”;
9. What will this line of code print out >>>
a) aRED b) fRED c) rRED d) none of the above
Ans: aRED(a)

10. What will this line of code print out >>> printf(“%c%s”, toupper( s2[ 1 ] ), &s1[ 1 ] );
a) RFRED b) RA c) RACK d) none of the above
Ans: RACK(c)