Connecting to the real world: files and streams M7 Test

  1. What happens if you try to compile and run this program assuming that the fopen() function operation succeeds?

    #include <stdio.h>
    int f(char t[]) {
         return t[0] - t[-1];
    }
    int main(void){
        int i = 2;
        i -= f("ABDGK" + 1);
        printf("%d", i);
        return 0;
    }
    • the program outputs 12A
    • the program outputs 12
    • the program outputs 1
    • the compilation or the execution fails
  2. What happens if you try to compile and run this program assuming that the fopen() function operation succeeds?

    #include <stdio.h>
    
    int main(void){
        FILE *f = fopen("file", "w");
        char c;
    
        fputs("12A", f);
        fclose(f);
        f = fopen("file", "r");
        fscanf(f, "%c", &c);
        fclose(f);
    
        printf("%c", c);
        return 0;
    }
    • the program outputs 1
    • the compilation or the execution fails
    • the program outputs 12A
    • the program outputs 12
  3. What happens if you try to compile and run this program assuming that the fopen() function operation succeeds?

    #include <stdio.h>
    
    int main(void){
         FILE *f = fopen("file", "w");
         int i;
    
        fputs("12A", f);
        fclose(f);
        f = fopen("file", "r");
        fseek(f);
        i = ftell(f, 0, SEEK_END);
        fclose(f);
    
        printf("%d", i);
        return 0;
    }
    • the program outputs 2
    • the program outputs 3
    • the compilation or the execution fails
    • the program outputs 1
  4. What happens if you try to compile and run this program assuming that the fopen() function operation succeeds?

    #include <stdio.h>
    int main(void) {
       FILe *f = fopen("file", "w");
       int i = fputs("Hello!", f);
    
      printf("%d", i != EOF);
      return 0;
    }
    • the program outputs 2
    • the compilation or the execution fails
    • the program outputs 0
    • the program outputs 1
  5. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        int i;
        i = fprintf(stdin, "HELLO!");
    
        printf("%d", i == EOF);
        return 0;
    }
    • the program outputs 2 
    • the program outputs 1
    • the program outputs 0 
    • the compilation or the execution fails
  6. What happens if you try to compile and run this program assuming that the fopen() function operation succeeds?

    #include <stdio.h>
    
    int main(void) {
        FILE *f = fopen("file", "w");
        int i = fputs(f, "HELLO!");
    
       printf("%d", i != EOF);
       fclose(f);
       return 0;
    }
    • the program outputs 2
    • the compilation or the execution fails
    • the program outputs 1
    • the program outputs 0
  7. What happens if you try to compile and run this program assuming that the fopen() function operation succeeds?

    #include <stdio.h>
    
    int main(void) {
        FILE *f = fopen("file", "w");
        int i;
    
        fputs("12A", f);
        fclose(f);
    
        f = fopen("file", "r");
        fseek(f, 0, SEEK_END);
        i = ftell(f);
        fclose(f);
    
        printf("%d", i);
        return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the compilation or the execution fails
    • the program outputs 3
  8. The following string:

    D:\USERDIR\jonhdoe.txt

    is a valid file name in:

    • MS Windows systems
    • Unix/Linux systems
  9. What happens if you try to compile and run this program assuming that the fopen() function operation succeeds?

    #include <stdio.h>
    
    int main(void) {
        char s[20];
        FILE *f = fopen("file", "w");
        int i = fputs("12A", f);
        fclose(f);
    
          f = fopen("file", "r");
        fgets(s, 2, f);
        puts(s);
        fclose(f);
        return 0;
    }
    • the program outputs 12
    • the compilation or the execution fails
    • the program outputs 1
    • the program outputs 12A
  10. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int i = 0;
    
    int *f(int *i) {
         (*i)++;
         return i;
    }
    
    int main(void)
    {
         int i = 1;
         i = *f(&i);
         
          printf("%d", i);
          return 0;
    }
    • the program outputs 2
    • the program outputs 1
    • the compilation or the execution fails
    • the program outputs 0
  11. The following string:

    #HomeDir/HomeFile

    is a valid file name in:

    • MS Windows systems
    • Unix/Linux systems
  12. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
         FILE *f = fopen("file", "w");
         float f;
    
         fputs("12A", f);
         fclose(f);
         f = fopen("file", "r");
         fscanf(f, "%f", &f);
         fscanf(f);
         
          printf("%f", f);
          return 0;
    }
    • the program outputs 0.000000
    • the program outputs 12.000000
    • the program outputs 1.000000
    • the compilation or the execution fails
  13. Unix/Linux system treat the following file names:

    JohnDone and Johndone

    as:

    • identical file names
    • different file names
  14. What happens if you try to compile and run this program?

    #include <stdio.h>
    int main(void)
    {
          char s[20];
          FILE *f = fopen("file", "w");
          int i = fputs("12A", f);
          fclose(f);
         
          f = fopen("file", "r");
          fgets(s, 20, f);
          puts(s);
          fclose(f);
          return 0;
    }
    • the program outputs 12A
    • the program outputs 12
    • the program outputs 1
    • the compilation or the execution fails
  15. What happens if you try to compile and run this program?

    int main(void)
    {
          FILE *f;
     
          f = fopen("file", "wb");
          printf("%d", f != NULL);
          fcolse(f);
              
          
          return 0;
    }
    • the compilation fails
    • the program outputs 0
    • the program outputs 1
    • the execution fails
  16. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void)
    {
         FILE *f;
         f = fopen("file", "wb");
          
          printf(%d, f != NULL);
          fcolse(f);
          return 0;
    }
    • the program outputs 2
    • the compilation fails
    • the program outputs1
    • the program outputs 0
  17. The following string:

    JohnDoe

    is a valid file name in:

    • MS Windows system only
    • Unix/Linux and MS Windows system
    • Unix/Linux system only
  18. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void)
    {
          FILE *f;
          int i = fprintf(f, "Hello!");
         
          printf("%d", i == EOF);
          return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs 0 
    • the compilation or the execution fails
  19. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void)
    {
         int i;
         i = fprintf(f, "Hello!");
         
          printf("%d", i == EOF);
          return 0;
    }
    • the program outputs 0 to the stdout stream
    • the program outputs 1 to the sttout strezm
    • the compilation or the execution fails
    • the program outputs 2  to the stdout stream
  20. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void)
    {
          FILE f;
          f = fopen("file", "wb");
         
          printf("%d", f != NULL);
          fcolse(f);
          return 0;
    }
    • the compilation  fails
    • the program outputs 1
    • the program outputs 0
    • the execution fails 
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments