C mock tests
Test yourself on the whole course, against the clock: questions from every module, then coding problems you solve and run right here. Your score comes at the end, with every answer explained.
Each mock test has 12 questions drawn from the lessons and up to 3 coding problems, and 45 minutes on the clock, which keeps running if you reload. Questions are worth a point each, and each coding problem 4 points, shared by its tests. Score 60% or more to pass; your best score is kept.
- 01Mock test 112 questions · 3 coding problems · 45 minutes · 24 points
- 02Mock test 212 questions · 3 coding problems · 45 minutes · 24 points
- 03Mock test 312 questions · 3 coding problems · 45 minutes · 24 points
Part A · 12 questions
- What is the first factorial too big for a 32-bit int?
- A function receives an int array and changes values[0]. Does the caller's array change?
- What does fopen return when it can't open a file?
- Why does scanf("%s", name) not need an & before name?
- In a hollow 5 by 5 square, which test decides where a star goes?
- What does printf("[%04d]", 7) print?
- The compiler says: expected ';' before 'return'. Where is the mistake most likely to be?
- A function changes arr[0] of the array it was passed. What happens to the caller's array?
- What does a condition like (n % 2 == 0) give in C?
- How many bytes does the string "code" occupy in a char array?
- How do you check that x is between 1 and 10 inclusive?
- Which format specifier prints an int?
Part B · 3 coding problems
Write each answer and run its tests as often as you like: everything is marked when you submit. Each problem is worth 4 points, shared by its tests.
- 1Fix the missing semicolonMedium · 4 points
This program doesn't compile. Find the mistake and fix it so it prints both lines.
Expected outputC is compiled before it runs
Loading the editor… - 2PalindromeMedium · 4 points
Read a word and print
yesif it reads the same backwards (ignoring case), otherwiseno.InputLevel
Expected outputyes
Loading the editor… - 3Bitwise operatorsMedium · 4 points
Read two whole numbers
aandband printa & b,a | b,a ^ banda << 1on one line.Input12 10
Expected output8 14 6 24
Loading the editor…
Part A · 12 questions
- In total % 3600 / 60, which part is worked out first?
- What happens in a switch when a matching case has no break?
- Given int a[3] = {5, 6, 7}; int *p = a;, what is p[1]?
- What does -7 / 2 give in C?
- What is wrong with #define SEATS 40;
- Which statement about C is true?
- Why is naive recursive Fibonacci slow?
- What does a compiler do?
- What does 2 ^ 3 evaluate to in C?
- With #define SQ(x) x * x, what is SQ(1 + 2)?
- What does return 0; at the end of main signal?
- How many moves does the Tower of Hanoi take with 4 disks?
Part B · 3 coding problems
Write each answer and run its tests as often as you like: everything is marked when you submit. Each problem is worth 4 points, shared by its tests.
- 1Sum and averageMedium · 4 points
Read two whole numbers and print their sum, then their average with two decimals.
Input3 4
Expected outputSum: 7 Average: 3.50
Loading the editor… - 2Leap yearMedium · 4 points
Read a year and print
Leap yearorNot a leap year.Input2024
Expected outputLeap year
Loading the editor… - 3Triangle typeHard · 4 points
Read three side lengths. Print
Not a triangleif any side is at least the sum of the other two; otherwiseEquilateral,IsoscelesorScalene.Input3 3 3
Expected outputEquilateral
Loading the editor…
Part A · 12 questions
- countUp(n) calls countUp(n - 1) first and prints n afterwards. What does countUp(3) print?
- Where does every C program start running?
- Which loop always executes its body at least once?
- What does 7 / 2 give when both are int?
- How do you check whether two C strings a and b contain the same text?
- What does (double) 7 / 2 evaluate to?
- A function takes a struct by value and changes a member. What does the caller see?
- int x = 5; int y = x++; What are x and y afterwards?
- A file already holds data. Which mode adds new data without erasing it?
- What stops a recursive function from calling itself forever?
- Why write (double)total / count?
- Why do C programs often put prototypes at the top?
Part B · 3 coding problems
Write each answer and run its tests as often as you like: everything is marked when you submit. Each problem is worth 4 points, shared by its tests.
- 1A character and the nextHard · 4 points
Read one character (skipping any spaces before it) and print its code, then the character after it in the code table.
Inputa
Expected output97 b
Loading the editor… - 2A digit's valueMedium · 4 points
Read one digit character and print the number it stands for, times 2.
Input7
Expected output14
Loading the editor… - 3Digits in orderHard · 4 points
Write
void print_digits(int n)that prints the digits of a positive number from left to right, one per line, using recursion (no arrays).Input1234
Expected output1 2 3 4
Loading the editor…