C Quiz

Welcome to your C Quiz!

No copyright. You can use questions from this quiz freely (as long as you are not a shitty teacher or something).

One rule: DO NOT GET HELP FROM THE INTERNET OR OTHER TOOLS!

Author: Me.

Feel free to reach out if you spot typos or errors.

→ Notation

A function that takes inputs of types I1, I2, ... and returns and output of type T is denoted as f : (I1, I2, ...) → T. For example,

  • f : char -> int denotes a function declared as int f(char);
  • f : (char -> int) -> void denotes a function declared as void f(int(*)(char));

→ ABI specification for the quiz

  1. Built-in types sizes and alignments

    • char: 1 byte, 1-byte alignment
    • short: 2 byte, 2-byte alignment
    • int: 4 byte, 4-byte alignment
    • long: 8 byte, 8-byte alignment
    • long long: 8 byte, 8-byte alignment
    • float: 4 byte, 4-byte alignment
    • double: 8 byte, 8-byte alignment
    • long double: 8 bytes, 8-byte alignment
    • T*: 8 bytes, 8-byte alignment
  2. Memory layout

    • Members of a struct are laid out in the reverse decleration order.
    • No attributes are used unless explicitly specified.
    • Struct members are padded by default.
    • Size of a struct is the multiple of its greatest member size by default.
  3. Pointer arithmetic

    • Pointers are 8 bytes.
    • Incrementing a pointer p of type T* by n results in n * sizeof(T) bytes jump.
  4. Additional notes

    • The system is little-endian (unless explicitly said otherwise).
    • The compiler is a 64-bit gcc compiler complying with C11 standard.
    • No compiler-specific flags are used unless explicitly specified.
    • char is signed by default.


Leave a Reply