Skills101
← C Programming — Intermediate

C Programming Intermediate — Test 1

15 questions19 minPass: 60%+30 XP on first passFree sample test

15 questions · 19 minutes · intermediate level, with an explanation for every answer.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What is the output?

    #include <stdio.h>
    int main() {
        int m[2][3] = {{1, 2, 3}, {4, 5, 6}};
        int s = 0;
        for (int i = 0; i < 2; i++)
            for (int j = 0; j < 3; j++)
                if (i == j || j == 2) s += m[i][j];
        printf("%d", s);
        return 0;
    }
    
  2. Question 2

    What is the output?

    #include <stdio.h>
    int counter() { static int c = 0; return ++c; }
    int main() {
        counter(); counter();
        printf("%d", counter());
        return 0;
    }
    
  3. Question 3

    What does malloc return when it cannot allocate memory?

  4. Question 4

    What is the difference between calloc and malloc?

  5. Question 5

    What is the output?

    #include <stdio.h>
    #define SQ(x) x * x
    int main() {
        printf("%d", SQ(2 + 3));
        return 0;
    }
    
  6. Question 6

    What is the output?

    #include <stdio.h>
    struct P { char c; int n; };
    int main() {
        struct P p = {'x', 7};
        struct P *q = &p;
        q->n += 3;
        printf("%c %d", p.c, p.n);
        return 0;
    }
    
  7. Question 7

    What is the output?

    #include <stdio.h>
    void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }
    int main() {
        int x = 3, y = 9;
        swap(&x, &y);
        printf("%d %d", x, y);
        return 0;
    }
    
  8. Question 8

    Which function frees memory from malloc/calloc?

  9. Question 9

    What is the output?

    #include <stdio.h>
    int main() {
        int a[] = {10, 20, 30, 40};
        int *p = a;
        p += 2;
        printf("%d %d %d", *p, *(p - 1), p[1]);
        return 0;
    }
    
  10. Question 10

    What is the output?

    #include <stdio.h>
    int f(int n) { return n <= 1 ? n : f(n - 1) + f(n - 2); }
    int main() {
        printf("%d", f(10));
        return 0;
    }
    
  11. Question 11

    What is the size of a union with members int i; double d; char c[3]; (typical 64-bit)?

  12. Question 12

    What is the output?

    #include <stdio.h>
    int main() {
        int x = 0x0F, y = 0x33;
        printf("%d %d %d %d", x & y, x | y, x ^ y, x << 2);
        return 0;
    }
    
  13. Question 13

    What is the difference between char *p = "hi"; and char a[] = "hi";?

  14. Question 14

    What is the output?

    #include <stdio.h>
    int main() {
        unsigned int u = 0;
        u = u - 1;
        printf("%d", u > 100);
        return 0;
    }
    
  15. Question 15

    What is the output?

    #include <stdio.h>
    int main() {
        char s[] = "racecar";
        int i = 0, j = 6, ok = 1;
        while (i < j) if (s[i++] != s[j--]) ok = 0;
        printf("%s", ok ? "palindrome" : "no");
        return 0;
    }
    
🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →