Quiz C1-2 | CS 2113 Software Engineering - Spring 2021

Quiz C1-2

Submit your answers via this Google Form

Question 1

This program doesn’t compile. Select the matching line that will fix the program.

typedef struct{
  int x;
  int y;
} point_t;

int main(){
  struct point_t a;
  a.x = 5;
  a.y = 10;
}

Question 2

What is the output of the program below?

#include <stdio.h>

int sum(int * array){
  int sum=0;
  for(int i=0;i<sizeof(array);i++){
     sum +=  array[i];
  }
  return sum;
}

int main(){
  int array[] = {1,2,3,4,5,6,7,8,9,10};
  int s = sum(array);  
  printf("%d\n",s);
}

Question 3

Select the correct memory diagram for the following program at point (1):

int main(){
   int array[3];
   int *p = &array[1];
   int *q = &array[2];
   
   array[0] = 2;
   *p = 8;
   *q = 4;

   array[2] = 12;  // <- point (1)
   
   int ** r; 
   r = &q;
   **r = 16;// <- point (2)
}

Question 4

Select the correct memory digraion for the program above at point (2)

Question 5

Select the appropriate line of code for <FILL-IN-HERE> that prints the member f of bar via FOO

#include <stdio.h>

int main(){

  struct bar{
    float f;
    double d;
  };

   struct foo{
      int i;
      int j;
      struct bar * BAR;
   };

   struct foo * FOO;
   
   // ... some code that sets up foo!
   
   printf("f=%g", <FILL-IN-HERE> ); //finish this line.
}