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

C Programming My teacher gave us quizzes to use as a study guide for our test. I

ID: 3851347 • Letter: C

Question

C Programming

My teacher gave us quizzes to use as a study guide for our test. I want to make sure I have the correct answers so I am studying the right material.

Thanks for the help!

Fill out the answer sheet with your choices and turn the quiz in. DO NOT PUT YOUR ANSWERS ON THIS SHEET – RECORD THEM ON THE ANSWER SHEET ONLY. Assume a character = 1 byte, int = 2 bytes, float = 4 bytes, double = 8 bytes.

#include

typedef struct _student{

      char name[50];

      int mark;

} student;

void print_list(student list[], int size);

void read_list(student list[], int size);

void main() {

      printf(“%d”, sizeof( student ) );

      const int size = 3;

      student list[size];

      read_list(list,size);

      print_list(list,size);

}

void read_list(student list[], int size) {

      printf("Please enter the student information: ");

      int i = 0;

      for(i = 0; i < size;i++){

            printf(" name:");

            scanf("%s",list[i].name);

            printf(" mark:");

            scanf("%d",&list[i].mark);

      }

}

void print_list(student list[], int size){

      printf("Students' information: ");

int i = 0;

      for(i = 0; i < size;i++){

            printf(" name: %s, mark: %d",list[i].name,list[i].mark);

}

}

1. (1 point) How many functions are in the code above?

2. (1 point) At which line of code above is memory allocated for the structure?

3. (1 point) Using the assumptions in question one, how much space will “list” require?

4. (1 point) Which line of code creates a pointer?

5. (4 points) How many student records will be processed by the program above?

6. What will the printf() on line “i” display?

7. (1 point) T   /    F A structure cannot contain an instance of itself.

8. (1 point) T   /    F Structure definitions do not reserve any space in memory.

9. (1 point) T   /    F When structures or individual structure members are passed to a function, they are passed by reference.

10. (1 point) If rand() returns 82, what will this print? printf(“%d”, 2 + (rand() %9));

Explanation / Answer

1. there are three funcitons including main function . The other two are print_list and read_list.

2.  student list[size]; - At this line memory is allocated. top defination is just defininig a datatype student using typedef and structure.

3. size of one student object = 54 ( 1 byte size of char so name has 50 byte size, 2 byte for int and 2 byte for pointers) So list have 54*3 = 162 bytes

4.

typedef struct _student{

      char name[50];

      int mark;

} student; //This line creates a pointer

5. 3 student records created as a list in main function, then that list is passed to read_list and print_list, which works on those 3 records only. So total 3 records are created and processed.

6. printf of line i in the following for loop : -

int i = 0;

      for(i = 0; i < size;i++){

            printf(" name: %s, mark: %d",list[i].name,list[i].mark);

}

Here printf displays name and mark of one student . eg a sample line print by printf is name: Bobby, mark:20

7. True: - because if it can create an instance, then we will need a variable which becomes its own instance and call constructor resulting in infinite recursive loop.

8. True: - Structure definition is just the part of source code, it does not have its own memory, it acts as a datatype of the variable and memory is assigned to that variable.

9. False:- They can be passed by value as well as reference. for reference we need to send the pointer to the structure using *.

10. This will print 3 as 82%9 is 1 and 2+1 = 3;