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

C Program Our teacher gave us quizzes to use as a study guide and I want to make

ID: 3851385 • Letter: C

Question

C Program

Our teacher gave us quizzes to use as a study guide and I want to make sure I did this correct. Thanks for the help!

There are 10 questions on this quiz. DO NOT PUT YOUR ANSWERS ON THIS SHEET – RECORD THEM ON THE ANSWER SHEET ONLY. Using the code below (IGNORE ALL COMPILE ERRORS):

Use the following code to answer the next few questions:

m. typedef enum { Holly, Tom, Julie, Fred } nameT;
n. nameT yyy;
o. yyy = RightFrom(Holly);
p.   printf(“%d”, yyy);
r.   nameT RightFrom(nameT xxx)
s.   {
t.        return ( ( xxx + 2 ) % 4 );
w.   }

1. What is the numerical value of “Holly”?

2. On what line of code is memory allocated for a nameT?

3. What value will printf() display?

4. Would the following code get past the compiler? yyy = Nancy;

5. A “data type” in C has two properties.
a) state and class      b) limit and structure           c) domain and set of operations     d) none of these

============================================================================
Using the code below (IGNORE ALL COMPILE ERRORS)

a.        #include <stdio.h>

b.        int sum(int n);

c.         int main(){

d.           int num,add;

e.            printf("Enter a positive integer: "));

f.             scanf("%d",&num);

g.             add=sum(num);

h.            printf("sum=%d",add);

j.          }

k.        int sum(int n){

m.           if(n=0)

n.               return n;

p.            else

r.                return n+sum(n-1);

s.         }

6) If I enter the number “4” for the scanf on line “f”, what will the output of this program look like IF ALL ERRORS WERE FIXED?

7) T    /     F   Recursion is not used in this code.

8) Which line of code has a compile error?

9) Which line of code above uses the address operator?

10) Which line of code has an error that will cause the program to execute improperly (think CS1050 level) ?

Explanation / Answer

Below are the answers. Please don't forget to rate the answer if it helped. Thank you very much.

1. What is the numerical value of “Holly”?

Holly will get a value of 0. enums are assigned int values automatically starting with 0 for the 1st one.

2. On what line of code is memory allocated for a nameT?

n. nameT yyy;

Only when a variable is declared, memory is allocated.

3. What value will printf() display?

It prints 2.

RightFrom(Holly) evaluates to (0 + 2 ) % 4 = 2

4. Would the following code get past the compiler? yyy = Nancy;

No. Nancy is not defined as a type in the program, so compiler will issue erors.

5. A “data type” in C has two properties.
a) state and class      b) limit and structure           c) domain and set of operations     d) none of these

option b. Every datatype has some associated size and different way of storage structure.

6) If I enter the number “4” for the scanf on line “f”, what will the output of this program look like IF ALL ERRORS WERE FIXED?

It will print the sum of 4 + 3 + 2+ 1 + 0 i.e. 10

7) T    /     F   Recursion is not used in this code.

True. Recursion is being used in the code, since the function sum calls itself at line r

8) Which line of code has a compile error?

line e has compiler error . There is an extra ) at the end before ;

9) Which line of code above uses the address operator?

line f uses the address operator &

10) Which line of code has an error that will cause the program to execute improperly (think CS1050 level) ?

line m has an error. Instead of using the operator for comparison == , a single = (assignment ) is used . This will set n to 0 and the program will not function as desired.