C Essentials – Final Test

  1. What is the value of the x variable at the end of the following snippet?

    int x = 1;
    
    x = x + 2 * x;
    x = x / 2 * x;
    x = x + 2 + x;
    • 1
    • 8
    • 4
    • 2
  2. Which of the following declarations is valid?

    • int long;
    • int int;
    • int float;
    • int longint;
  3. What happens if you try to compile and run this program?

    #include <stdio.h>
    int mian(void) {
        int t[4] = {0, -1, -2, -3}, *p = t + 3;
    
        printf("%d\n", p[*p] - t[2]);
        return 0;
    }
    • the program outputs 1
    • the program outputs 8
    • the program outputs 4
    • the program outputs 2
  4. What happens if you try to compile and run this program?

    #include <stdio.h>
    struct S{
        int Var;
        struct S * Str;
    };
    
    int main(void) {
        struct S S[] = {{8, NULL}, {4, &S[0]}, {2, &S[1]}};
        printf("%d", S[2].Str->Var);
        return 0;
    }
    • the program outputs 8
    • the program outputs 1
    • the program outputs 2
    • the program outputs 4
  5. What happens if you try to compile and run this program?

    #include <stdio.h>
    int main(void) {
        int i = 16, j = 8;
        do {
             i /= 2;
             j = i / 2;
        }while(j > 0);
              printf("%d", i + j);
        return 0;
    }
    • the program enters an infinite loop and outputs nothing 
    • the program outputs 4
    • the program outputs 1
    • the program outputs 2
  6. What happens if you try to compile and run this program?

    #include <stdio.h>
    #define ABC 10
    #define XYZ ABC - 1
    
    int main(void) {
        int i = 19;
        i = i - XYZ;
    
        printf("%d\n", i);
        return 0;
    }
    • the program outputs 4
    • the program outputs 1
    • the program outputs 8
    • the program outputs 2
  7. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        char *t1 [10];
        char *t2 [10];
    
        printf("%d", (sizeof(t1) == sizeof(t2)) + sizeof(t1[0]));
        return 0;
    }
    • the program outputs 1
    • the program outputs 4
    • the program outputs 2
    • the program outputs 8
  8. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        char s[20];
        FILE *f = fopen("data", "w");
        int i = fputs("1248", f);
        fclose(f);
        f = fopen("data", "r");
        fgets(s + 2, 4, f);
        putchar(s[4]);
        fclose(f);
        return 0;
    }
    • the program outputs 8
    • the program outputs 2
    • the program outputs 4
    • the program outputs 1
  9. What is the value of the following floating-point literal?

    -1E-1
    • -0.1
    • -1.0
    • -0.01
    • the literal is valid
  10. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        int i = 5, j = 4;
        for(i--; i--; i--)
            j--;
        printf("%d", i + j);
        return 0;
    }
    • the program outputs 1
    • the program enters an infinite loop and outputs nothing 
    • the program outputs 4
    • the program outputs 2
  11. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        int i, s = 0, t[] = {0, 1, 2, 4, 8, 16};
      
        for(i = 2; t[i] < 8; i *= 2) 
            s += t[i];
            
             printf("%d\n", s);
         return 0;
    }
    • the program outputs 0
    • the program outputs 2
    • the program outputs 4
    • the program outputs 1
  12. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int fun(int *t) {
        return * (++t);
    }
    
    int main(void) {
        int arr[] = {8, 4, 2, 1};
    
        printf("%d\n", fun(arr + 2));
        return 0;
    }
    • the program outputs 1
    • the program outputs 1
    • the program outputs 4
    • the program outputs 8
  13. Which of the following string is a legal variable name?

    • Alpha_Omega
    • Alpha:Omega
    • Alpha@Omega
    • Alpha-Omega
  14. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        int t[4][4];
    
        printf("%d\n", sizeof(t) / sizeof(t[0]) / sizeof(t[0][0]));
        return 0;
    }
    • the program outputs 2
    • the program outputs 1
    • the program outputs 4
    • the program outputs 8
  15. What happens if you try to compile and run this program?

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    struct S {
         char * S;
    };
    
    int main(void) {
        struct S *S = (struct S *) malloc(sizeof(struct S));
        S -> S = "abc";
    
        printf("%d", strlen(S -> S + 2) + S -> S[3]);
        free(S);
        return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs 8
    • the program outputs 4
  16. What is the meaning of the following declaration?

    void (*f) (int);
    • f is a pointer to function (int) returning int;
    • f is a function  (int)returning pointer to  void;
    • f is a pointer to function (int) returning void;
    • the declaration is erronous
  17. Which of the following is are legal variable names?

    • 2R2D
    • R2D2
    • _R2D2_
    • _2R2D_
  18. What is the value of the x variable at the end of the following snippet?

    int x = 1;
    
    x = x * x + 2;
    x = x / x * 2;
    x = x + 2 + x;
    • 2
    • 8
    • 6
    • 4
  19. What is the value of the following integer literal?

    0x12
    • 10
    • 18
    • the literal is invalid 
    • 12
  20. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    struct S{
          int S[2];
    };
    
    void f(struct S *S) {
        S -> S[1] = S -> S[0] + 2;
    }
    
    int main(void) {
        struct S S = {{4, 8}}, *p = &S;
        f(P);
        printf ("%d", S.S[1] / S.S[0]);
        return 0;
    }
    • the program outputs 8
    • the program outputs 4
    • the program outputs 1
    • the program outputs 2
  21. Select the proper form for the following declaration:

    ptr is a pointer to pointer to void

    • void ptr;
    • the declaration is invalid and cannot be coded in C
    • void *ptr;
    • void **ptr;
  22. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        int i = 1, j = 0, k;
    
        k = (i << j) + (j << i) + (i << i) + (j << j);
        k >>= i;
    
        printf("%d", k);
        return 0;
    }
    • the program outputs 0
    • the program outputs 4
    • the program outputs 1
    • the program outputs 2
  23. What is the value of the x variable at the end of the following snippet?

    int x;
    x = 'b' - 'a' * ('\' / '\');
    •  2
    • 0
    • 1
    • the snippet is invalid and will cause compilation error
  24. What is the value of the x variable at the end of the following snippet?

    int x = 1, y = 2, z;
    z = x / y * --x * y++;
    • 1
    • 0
    • 4
    • 2
  25. What is the value of the x variable at the end of the following snippet?

    #include <stdio.h>
    int main(void) {
        int i = 1, j = 0, k;
    
            k = (i & j) + (i | j) + (i ^ j) + !i + j;
            
            printf("%d", k);
         return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs 4
    • the program outputs 0
  26. What is the value of the following integer literal?

    012
    • 18
    • the literal is invalid
    • 10
    • 12
  27. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int f(int v) {
          v = 2 * v;
        return v * v;
    }
    
    int main(void) {
        int i = 2;
        f(i);
    
        printf("%d", i);
        return 0;
    }
    • the program outputs 8
    • the program outputs 2
    • the program outputs 4
    • the program outputs 1
  28. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        int i = 16, j = 6;
        while(j > 0) {
           i /= 2;
           j -= i / 2;
        }
            printf("%d", i + j);
        return 0;
    }
    • the program enters an infinite loop and outputs nothing
    • the program outputs 4
    • the program outputs 1
    • the program outputs 2
  29. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        int i, t[4];
      
        for(i = 0; i < 3; i++) {
           t[i] = i;
           t[i + 1] = 2 * t[i];
        }
           printf("%d\n", t[3]);
        return 0;
    }
    • the program outputs 0
    • the program outputs 2
    • the program outputs 1
    • the program outputs 4
  30. Which of the following strings is a legal floating-point number (in the “C” language sense)?

    • 3.1415M92
    • 3.1415F92
    • 3.1415X92
    • 3.1415E92
  31. What happens if you try to compile and run this program?

    #include <stdio.h>
    #include <string.h>
    
    int main(void) {
        char tt[20] = "0123456789";
        strcat(tt + 2, "987");
    
        printf("%d\n", strlen(tt) - tt[5] + '0');
        return 0;
    }
    • the program outputs 1
    • the program outputs 8
    • the program outputs 4
    • the program outputs 2
  32. What happens if you try to compile and run this program?

    #include <stdio.h>
    #include <string.h>
    
    int main(void) {
        char tt[20] = "0123456789";
        strcpy(tt, tt + 2);
    
        printf("%d\n", strlen(tt) - tt[9] + '5');
        return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs 4
    • the program outputs 8
  33. What happens if you try to compile and run this program?

    #include <stdio.h>
    #include <string.h>
    
    char *f(int p, char *s) {
         s[p + 1] = '\0';
         return s + 1;
    }
    
    int main(void) {
        char s[] = "ABCDEF";
        int i = strlen(f(1, s + 2));
    
        printf("%d\n", i);
        return 0;
    }
    • the program outputs 1
    • the program outputs 8
    • the program outputs 2
    • the program outputs 4
  34. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        int i = 2, j;
    
            for(j = 0; j < 0; j -= i)
            i /= 2;
    
            printf("%d", i + j);
         return 0;
    }
    • the program enters an infinite loop and outputs nothing
    • the program outputs 1
    • the program outputs 4
    • the program outputs 2
  35. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        int i, t[4];
    
        for(i = 3; i; i--) {
            t[i] = i - 1;
            t[t[i]] = t[i];
        }
            printf("%d\n", t[0]);
        return 0;
    }
    • the program outputs 2
    • the program outputs 4
    • the program outputs 0
    • the program outputs 1
  36. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        int i = 1, j = i + 2 * i;
        switch(j) {
             default: j = 0;
             case 1: j++; break;
             case 2: j--;
             case 0: j++; break;
        }
             printf("%d", ++j);
         return 0;
    }
    • the program outputs 0
    • the program outputs 1
    • the program outputs 2
    • the program outputs 4
  37. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    struct S {
           int S[2];
    };
    
    void f(struct S S) {
          S.S[0] = S.S[1] + 4;
    }
    int main(void) {
        struct S S = {{4, 8}};
        f(S);
    
        printf("%d", S.S[1] / S.S[0]);
        return 0;
    }
    • the program outputs 4
    • the program outputs 1
    • the program outputs 8
    • the program outputs 2
  38. What happens if you try to compile and run this program?

    #include <stdio.h>
    int main(void) {
        int i = 0;
        if(i = 1)
           i = 2;
        else
           i = 3;
           printf("%d\n", i);
        return 0;
    }
    • the program outputs 1
    • the program outputs 3
    • the program outputs 4
    • the program outputs 2
  39. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    char *f(char *p) {
         return p++;
    }
    char *g(char *p){
         return p += 2;
    }
    
    int main(void) {
        char *s = "ABCDEFGHIJ";
        char p = *f(g(f(s + 6)));
    
        printf("%d", p - 'A');
        return 0;
    }
    • the program outputs 4
    • the program outputs 1
    • the program outputs 8
    • the program outputs 2
  40. What happens if you try to compile and run this program?

    #include <stdio.h>
    int main(void) {
        int a = -1, b = 1;
        float i = 2.0, j = -2.0;
    
        printf("%d\n", (a > b) + (b > a) + (i > j) + (j > i) + ('z' > 'a'));
        return 0;
    }
    • the program outputs 2
    • the program outputs 1
    • the program outputs 3
    • the program outputs 4
  41. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        float x = 3.0, y = 2.0;
        int i = 1, j = 2;
        x = (int)x / y + (float)i / j;
    
        printf("%f", x);
        return 0;
    }
    • the program outputs2.000000
    • the program outputs 3.000000
    • the program outputs 0.000000
    • the program outputs 1.000000
  42. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int f(int t[][2]) {
         return t[0][0] + t[0][1];
    }
    int main(void) {
        int i, t[2][2] = {{0,4}, {4,2}};
        i = f(t);
    
        printf("%d", i);
        return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs 8
    • the program outputs 4
  43. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        char *p = "\0\4\1\3\2";
    
        printf("%d\n", p[p[1]] + *(p + 1) + p[4]);
        return 0;
    }
    • the program outputs 1
    • the program outputs 8
    • the program outputs 2
    • the program outputs 4
  44. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        int i = 1, j = i + 2 * i;
    
        switch(j - i) {
              case 1: j++;
              case 2: j--;
              case 0: j++; break;
              default: j = 0;
        }
              printf("%d", ++j);
        return 0;
    }
    • the program outputs 1
    • the program outputs 4
    • the program outputs 2
    • the program outputs 0
  45. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int fun(int t) {
         return ++t;
    }
    
    int main(void) {
        int arr[] = {8, 4, 2, 1};
    
        printf("%d\n", fun(arr[3]) + arr[2]);
        return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs 4
    • the program outputs 8
  46. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        char t[] = {'a', 'z', 'B', 'Z', '0'};
    
        printf("%d\n", t[t[1] - t[0] - t[3] + t[2] + 3] - t[4]);
        return 0;
    }
    • the program outputs 4
    • the program outputs 2
    • the program outputs 0
    • the program outputs 1
  47. Which of the following is a valid integer number (in the “C” language sense)?

    • 3_141_592
    • 3.141592
    • 3141592
    • 3,141592
  48. What happens if you try to compile and run this program?

    #include <stdio.h>
    #include <string.h>
    
    struct S {
         char S[4];
    };
    
    int main(void) {
        struct S S = {'a', 'b'};
    
        printf("%d", sizeof(S.S) - strlen(S.S) + S.S[3]);
        return 0;
    }
    • the program outputs 4
    • the program outputs 8
    • the program outputs 2
    • the program outputs 1
  49. What happens if you try to compile and run this program?

    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void) {
        int *t = (int *) malloc(sizeof(int) + sizeof(int));
        t++;
        *t = 8;
        t[ 1] = *t / 2;
        t--;
        t[1] = *t / 2;
    
        printf("%d\n", *t);
        free(t);
        return 0;
    }
    • the program outputs 2
    • the program outputs 1
    • the program outputs 8
    • the program outputs 4
  50. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        char a = 'A', *b = &a, **c = &b;
        **c = a + (a == *b);
    
        printf("%c", a);
        return 0;
    }
    • the program outputs C
    • the program outputs NULL
    • the program outputs B
    • the program outputs A
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments