
C Quiz
Test your C skills
30 multiple-choice questions. Tap an option in any question to check it instantly — your score updates as you go.
1
What function is used to read a line from a file in C?
🎉Correct! fgets() reads a line from a file into a buffer.
🤔Not quite. Think about which function handles string input efficiently.
2
Which header file is required to use printf() and scanf()?
🎉Correct! <stdio.h> declares the standard input/output functions.
🤔Not quite. It stands for "standard input/output".
3
What is the size of a char in C, in bytes?
🎉Correct! A char is always exactly 1 byte in C.
🤔Not quite. char is the smallest addressable type — it is guaranteed to be 1.
4
Which format specifier prints an integer with printf()?
🎉Correct! %d prints a signed decimal integer.
🤔Not quite. The "d" stands for decimal integer.
5
What is the index of the first element of an array in C?
🎉Correct! C arrays are zero-indexed, so the first element is at index 0.
🤔Not quite. C arrays start counting from zero.
6
Which operator returns the memory address of a variable?
🎉Correct! The & (address-of) operator gives a variable's address.
🤔Not quite. It is the same symbol used with scanf() to store input.
7
Which operator dereferences a pointer (accesses the value it points to)?
🎉Correct! The * operator dereferences a pointer to read/write its target.
🤔Not quite. It is the same symbol used when you declare a pointer.
8
Which loop is guaranteed to execute its body at least once?
🎉Correct! do-while checks its condition after running the body once.
🤔Not quite. One loop tests the condition at the bottom, not the top.
9
Which function allocates memory dynamically at runtime?
🎉Correct! malloc() reserves a block of memory on the heap.
🤔Not quite. It is declared in <stdlib.h> and returns a void*.
10
Which function releases memory that was allocated with malloc()?
🎉Correct! free() returns dynamically allocated memory to the heap.
🤔Not quite. C has no delete keyword — it uses a plain function.
11
What is the conventional return type of main() in standard C?
🎉Correct! main() returns int — the program's exit status.
🤔Not quite. It returns a status code to the operating system.
12
Which escape sequence represents a newline?
🎉Correct! \n moves output to the next line.
🤔Not quite. The letter "n" is a hint here.
13
What does the sizeof operator return?
🎉Correct! sizeof gives the size, in bytes, of a type or variable.
🤔Not quite. It is about memory footprint, not the stored value.
14
Which keyword declares a value that cannot be changed?
🎉Correct! const marks a variable as read-only.
🤔Not quite. C has no "final" keyword — think read-only.
15
What is the value of 5 % 2 in C?
🎉Correct! The % operator returns the remainder, which is 1.
🤔Not quite. % gives the remainder of integer division.
16
Which format specifier is used to print a float?
🎉Correct! %f prints a floating-point number.
🤔Not quite. The "f" stands for float.
17
What is the logical AND operator in C?
🎉Correct! && is the logical AND; a single & is bitwise AND.
🤔Not quite. The logical version doubles the symbol.
18
How do you write a single-line comment in C?
🎉Correct! // starts a single-line comment (since C99).
🤔Not quite. It is the same style used in C++ and JavaScript.
19
Which statement immediately exits the nearest loop?
🎉Correct! break terminates the enclosing loop or switch.
🤔Not quite. One keyword ends the loop; another only skips an iteration.
20
Which statement skips to the next iteration of a loop?
🎉Correct! continue jumps to the loop's next iteration.
🤔Not quite. It does not exit the loop — it just moves on.
21
Which function returns the length of a string?
🎉Correct! strlen() counts characters up to the null terminator.
🤔Not quite. It is declared in <string.h>.
22
Which function compares two strings?
🎉Correct! strcmp() returns 0 when two strings are equal.
🤔Not quite. The "cmp" part is short for compare.
23
What character terminates a C string in memory?
🎉Correct! C strings end with the null character \0.
🤔Not quite. It is an invisible character with value zero.
24
How do you correctly declare a pointer to an int?
🎉Correct! int *p; declares p as a pointer to int.
🤔Not quite. A pointer declaration uses the * symbol.
25
Which mode opens a file for reading with fopen()?
🎉Correct! fopen(name, "r") opens an existing file for reading.
🤔Not quite. The letter matches the word "read".
26
What is the default value of an uninitialized global int?
🎉Correct! Globals (static storage) are zero-initialized to 0.
🤔Not quite. Global/static variables are set to zero, unlike locals.
27
Which of these is a valid C variable name?
🎉Correct! _total is valid — names may start with a letter or underscore.
🤔Not quite. A name can't start with a digit, contain a hyphen, or be a keyword.
28
What does the && in an if-condition evaluate to when both sides are true?
🎉Correct! A true logical expression evaluates to 1 in C.
🤔Not quite. C represents true as 1 and false as 0.
29
Which symbol ends most statements in C?
🎉Correct! Statements in C end with a semicolon.
🤔Not quite. It is the most common cause of "expected ;" errors.
30
What is the correct syntax to include a standard header?
🎉Correct! Standard headers use #include <...> with angle brackets.
🤔Not quite. It starts with # and wraps the name in angle brackets.