Skills101
← C Programming — Advanced

C Programming Advanced — Test 1

15 questions22 minPass: 60%+40 XP on first passFree sample test

15 questions · 22 minutes · advanced 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>
    void rev(char *s, int i, int j) { if (i >= j) return; char t = s[i]; s[i] = s[j]; s[j] = t; rev(s, i + 1, j - 1); }
    int main() {
        char s[] = "skills";
        rev(s, 0, 5);
        printf("%s", s);
        return 0;
    }
    
  2. Question 2

    What is the output?

    #include <stdio.h>
    int main() {
        const char *s[] = {"red", "green", "blue"};
        const char **pp = s;
        pp++;
        printf("%s %c %c", *pp, **pp, *(*(pp + 1) + 2));
        return 0;
    }
    
  3. Question 3

    What is wrong with int *f() { int x = 5; return &x; }?

  4. Question 4

    What is the output?

    #include <stdio.h>
    int apply(int (*f)(int), int x) { return f(f(x)); }
    int twice(int n) { return 2 * n; }
    int inc(int n) { return n + 1; }
    int main() {
        printf("%d %d", apply(twice, 3), apply(inc, 3));
        return 0;
    }
    
  5. Question 5

    What does the volatile qualifier tell the compiler?

  6. Question 6

    What is the output?

    #include <stdio.h>
    int main() {
        int a = 5;
        int b = sizeof(a++);
        printf("%d %d", a, b);
        return 0;
    }
    
  7. Question 7

    What is the output?

    #include <stdio.h>
    struct S { char a; int b; char c; };
    struct T { int b; char a; char c; };
    int main() {
        printf("%d %d", (int)sizeof(struct S), (int)sizeof(struct T));
        return 0;
    }
    
  8. Question 8

    Where are memory blocks from malloc allocated?

  9. Question 9

    What is the output?

    #include <stdio.h>
    int f(int *p) { *p += 5; return *p; }
    int main() {
        int v = 1;
        int r = f(&v) + f(&v);
        printf("%d %d", r, v);
        return 0;
    }
    
  10. Question 10

    What is the output?

    #include <stdio.h>
    #include <stdlib.h>
    int main() {
        int n = 4;
        int *arr = malloc(n * sizeof(int));
        for (int i = 0; i < n; i++) arr[i] = i * i;
        arr = realloc(arr, 6 * sizeof(int));
        arr[4] = 16; arr[5] = 25;
        int s = 0;
        for (int i = 0; i < 6; i++) s += arr[i];
        free(arr);
        printf("%d", s);
        return 0;
    }
    
  11. Question 11

    What is the output?

    #include <stdio.h>
    int main() {
        int a[] = {1, 2, 3, 4, 5};
        int *p = (int *)(&a + 1);
        printf("%d %d", *(a + 1), *(p - 1));
        return 0;
    }
    
  12. Question 12

    What is a dangling pointer?

  13. Question 13

    What is the output?

    #include <stdio.h>
    int main() {
        int i = 3;
        int *p = &i, **q = &p;
        **q = *p * 2 + 1;
        printf("%d %d", i, *p == **q);
        return 0;
    }
    
  14. Question 14

    What is the output?

    #include <stdio.h>
    int main() {
        int x = 1;
        char *c = (char *)&x;
        printf("%s", *c ? "little" : "big");
        return 0;
    }
    
  15. Question 15

    Which is undefined behaviour in C?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →