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

Quiz C0-2

Submit your answers via this Google Form

Question 1

Below are Java print statements. Write the C equivalent print statement.

int a = 5
int b = 2;
float c = 4.4;
System.out.println("a = "+a+" b="+b+" c="+c);

Question 2

The C program below doesn’t write anything to a file, select the correct replacement lines that will make the program work as desired.

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char * argv[]){

  FILE * stream = fopen("helloworld.txt", "r");

  fprintf(stream, "Hello World!\n");

  fclose(stream);
}

Question 3

What is the output of this C program?

int main(){
   float f = 3.14;
   int n = 10;
   printf("%d %f\n",f,n);
}

Question 4

Choose the correct way(s) to print an error message to stderr when a fopen() fails like in the following code snippet:

if( fopen( /* ... */) == NULL){
  // WHAT GOES HERE?!
}