C Essentials – Part 2: SUMMARY TEST

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

    int X = 8;
    X = X - X / 2;
    X = X * X / 4;
    X = X + 2 * X;
    • 16
    • 10
    • 12
    • 14
  2. 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->Str->Var);
        return 0;
    }
    • the program outputs 1
    • the program outputs 8
    • the program outputs 4
    • the program outputs 2
  3. What is the value of the X variable at the following snippet?

    float X = 2.0;
    X = X + X * X;
    X = X / X * X;
    X = X / X + X;
    • 0.500000
    • 110.000000
    • 11.000000
    • 1.000000
  4. What happens if you try to compile and run this program?

    #include <stdio.h>
    
    int main(void) {
        char *p = "\0\2\1\3\4";
    
             printf("%d", p[p[2] + *(p + 1) + p[0]);
        return 0;
    }
    • the program outputs 2
    • the program outputs 4
    • the program outputs 8
    • the program outputs 1
  5. 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 + 11, "123");
    
        printf("%d\n", strlen(tt) - tt[8] + '0');
        return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs 8
    • the program outputs 4
  6. What happens if you try to compile and run this program?

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

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

    #include <stdio.h>
    
    int main(void) {
        int i = 3, j = i - 2 * i;
        switch(i j){
           case 1: j++;
           case 2: j--;
           case 3: j++; break;
           default: j = 0;
        }
    
        printf("%d", ++j);
        return 0;
    }
    • the program outputs 4
    • the program outputs 0
    • the program outputs 2
    • the program outputs 1
  9. 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->Str->Var);
        return 0;
    }
    • the program outputs 3
    • the program enters an infinite loop and outputs nothing
    • the program outputs 1
    • the program outputs 2
  10. What is the value of the following integer literal?

    017
    • the literal is invalid
    • 15
    • 17
    • 23
  11. What happens if you try to compile and run this program?

    #include <stdio.h>
    int main(void) {
        char t[] = { 'x', 'z', 'Y', 'Z', '2' , '0' };
        printf("%d\n", t[t[1] - t[0] - t[3] + t[2] + 3] - t[5]);
        return 0;
    }
    • the program outputs 0
    • the program outputs 1
    • the program outputs 4
    • the program outputs 2
  12. What is the value of the Z variable at the end of the following snippet?

    int X = 1;
    int Y = X + 2;\
    
    y++;
    int Z = Y;
    --x;
    y--;
    Z = Z/ y * X * Y;
    • 3
    • 0
    • 1
    • 7
  13. Which of the following declarations is legal?

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

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

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

    #include <stdio.h>
    int main(void) {
        float a = 3.14E0, *b = &a, **c = &b;
        **c = a + (a == *b);
    
        printf("%d", a);
        return 0;
    }
    • the program outputs 2.140000
    • the program outputs 3.140000
    • the program outputs NULL
    • the program outputs 4.140000
  17. What happens if you try to compile and run this program?

    #include <stdio.h>
    #include <stlib.b>
    
    int main(void) {
        float *t = 1 + (float *) malloc(sizeof(float) * sizeof(float));
        t--;
        *t = 8.0;
        t[1] = *t / 4.0;
        t++;
        t[-1] = *t / 2.0;
    
        printf("%f\n", *t);
        free(--t);
        return 0;
    }
    • the program outputs 2.000000
    • the program outputs 8.000000
    • the program outputs 1.000000
    • the program outputs 4.000000
  18. What is the value of the X variable at the end of the following snippet?

    int X;
    X = ('r' - 's') * ('A' / 'Z');
    • 1
    • 0
    • the snippet is invalid and will cause compilation error
    • 2
  19. What happens if you try to compile and run this program?

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

    #include <stdio.h>
    
    int main(void) {
        char t[4][4];
    
        printf("%d",sizeof(t) / sizeof(t[0]) / sizeof(t[0][0]));
        return 0;
    }
    • the program outputs 8
    • the program outputs 2
    • the program outputs 1
    • the program outputs 4
  21. Which of the following string is the correct floating-point number(in the “C” language sense)?

    • 3E8
    • 3,0x10^8
    • 300,000,000
    • 3.0x10^8
  22. What happens if you try to compile and run this program?

    #include <stdio.h>
    int main(void) {
        int i, s = 0, t[] = {16, 8, 4, 2, 1, 0};
    
        for(i = 5; t[i] > 2; i /= 2)
           s += t[i];
    
        printf("%d\n", s);
        return 0;
    }
    • the program outputs 0
    • the program outputs 1
    • the program outputs 2
    • the program outputs 4
  23. Select the proper from for the following declaration:

    ptr is a pointer to pointer to pointer to double

    • the declaration is invalid and cannot be coded in C
    • doube ***ptr;
    • double **ptr;
    • double *ptr;
  24. 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] = 4 - i;
           t[i + 1] = 2 * t[i];
        }
    
        printf("%d\n", t[2]);
        return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs 0
    • the program outputs 4
  25. What happens if you try to compile and run this program?

    #include <stdio.h>
    int main(void) {
        char s[20] = "?";
        FILE *f = fopen("fopen","w");
        int i = fputs("789",f);
        fclose(f);
        f = fopen("fopen","r");
        fgets(s + 1,3,f);  
    
        printf("%c\n", s[2] - s[3]);
        fclose(f);
        return 0;
    }
    • the program outputs 8
    • the program outputs 1
    • the program outputs 4
    • the program outputs 2
  26. 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 = "123\0""45678";
    
        printf("%d",strlen(S -> S + 5) + S -> S[3]);
        free(S);
        return 0;
    }
    • the program outputs 1
    • the program outputs 2
    • the program outputs 4
    • the program outputs 8
  27. What happens if you try to compile and run this program?

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

    #include <stdio.h>
    
    int main(void) {
        int i = -1, j = 1;
        
        for(i++; i++; i++)
           j++;
    
        printf("%d", i + j);
        return 0;
    }
    • the program outputs 2
    • the program outputs 1
    • the program outputs enters an infinite loop and outputs nothing
    • the program outputs 3
  29. 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 2
    • the program outputs 1
    • the program outputs 4
  30. What is the meaning of the following declaration?

    float *f(int);
    • f is function (int) returning pointer to float;
    • f is a pionter to function (int) returning float;
    • the declaration is erronous
    • f is a pointer to function (float) returning int;
  31. What is the value of the following integer literal?

    0x17

    • 23
    • the literal is invalid
    • 17
    • 15
  32. Which of the following string is  a legal variable name?

    • 2antiworld
    • anti_world
    • anti world
    • anti:world
  33. What happens if you try to compile and run this program?

    #include <stdio.h>
    float f(float v) {
           v = v / 2.0;
       return v + v;
    }
    
    int main(void) {
        float x = 4;
        f(x);
    
        printf("%f", x);
        return 0;
    }
    • the program outputs 4.000000
    • the program outputs 2.000000
    • the program outputs 8.000000
    • the program outputs 1.000000
  34. 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 + 2] = '\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 4
    • the program outputs 8
    • the program outputs 2
  35. What happens if you try to compile and run this program?

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

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

    #include <stdio.h>
    int main(void) {
        int i = 1;
    
        if(i = 0)
             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
  38. What happens if you try to compile and run this program?

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

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

    #include <stdio.h>
    
    int main(void) {
        int x = 1, y = 1;
        float k = -1e0, m = 2el;
    
        printf("%d\n", (x >= y) + (x >= y) + (k >= y) + (m >= k) + ('q' <= 'z'));
        return 0;
    }
    • the program outputs 2
    • the program outputs 4
    • the program outputs 1
    • the program outputs 2
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments