C Program This is a study guide for a test! 1) (1) After this line of code execu
ID: 3852141 • Letter: C
Question
C Program
This is a study guide for a test!
1) (1) After this line of code executes what will be the value of “result”?
int result = 7 % 12;
2) (1) After this line of code executes what will be the value of “result”?
int result = 23 + 5 * 2 * 3 / 2 – 6 + 12 / 2;
3) (1) What will be the value of “sumtotal” when this code is executed?
int n1 = 4, n2 = 7, n3 = 2, sumtotal = 5;
if (n1 ! = 4)
sumtotal += n3;
else if (n3 <= 5)
sumtotal = n2++;
else sumtotal -= n1;
4) (1) What is the final value of “y” after this for loop is finished?
for (y = 3; y<=11; y+=2)
5) (1) What will the following C code print out?
int x = 4, y = 6;
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
Examine the following code and answer question 6 below. IGNORE COMPILE ERRORS.
int j = 0;
for (j = 0; j <= 9; j++)
{ printf( “%d”, 1 + ( rand() % 6 )); }
6) (1) What are the POSSIBLE range of numbers that will be printed by the “printf()” statement above?
7) (1) T / F All of the curves in a given complexity class do not share the same basic shape.
8) (1) Fill in the following blanks from the Big O notation comparison we discussed in the space on the answer sheet.
When using dynamic memory allocation
9) (1) T / F pointers do take up space and using these algorithms will incur the overhead of
function calls that do slow down execution of your program.
10) (1) T / F can save memory vs. arrays due to their ability to grow and shrink
Explanation / Answer
1) mod (x,y) gives the remainder of the given number x and y
7%12 returns the value 7
2 )
after this line of code executes
int result = 23 + 5 * 2 * 3 / 2 – 6 + 12 / 2;
23 +30/2 -6+6
23 +15+6-6
result : 38
3) the value of “sumtotal” will be
int n1 = 4, n2 = 7, n3 = 2, sumtotal = 5;
if (n1 ! = 4)
sumtotal += n3;
else if (n3 <= 5)
sumtotal = n2++;
else sumtotal -= n1;
sumtotal is 7 because sumtotal = n2++ assigns the value and increment the n2 by 1
4 ) the value of y in for (y = 3; y<=11; y+=2)
y is 13. it increments the y value by 2 and check the condition, now the condition fails it returns.
5)
int x = 4, y = 6;
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
result option b. if condition (x > 5) fails so it executes the else part and print the value "x<=15"
6) for (j = 0; j <= 9; j++)
{ printf( “%d”, 1 + ( rand() % 6 )); }
print statement will print 2,3,4,5,6
7) false
SHAPE is a base class, all the class must derived from the base class.
8) in dynamic allocation memory is allocated when its needed, there will be effective use of memory during runtime.
9) false pointer will not slow down the execution because it directly points to the location where the values of the variable is stored
10) false array are fixed number of contiguous elements. it cant grow in size or shrink
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.