Unlock hundreds more features
Save your Quiz to the Dashboard
View and Export Results
Use AI to Create Quizzes and Analyse Results

Sign inSign in with Facebook
Sign inSign in with Google

Online C Practice Quiz

Sharpen your coding skills with interactive questions

Difficulty: Moderate
Grade: Grade 12
Study OutcomesCheat Sheet
Colorful paper art promoting Online C Code Challenge quiz for students to test programming skills

Which of the following is the correct syntax to print "Hello, World!" in C?
System.out.println("Hello, World!");
cout << "Hello, World!";
printf("Hello, World!");
echo "Hello, World!";
The printf function is part of the C standard library and is used to output text to the console. The other options represent syntax from C++, Java, and PHP respectively.
What is the purpose of the #include directive in a C program?
To link the C program with the operating system.
To include the standard input/output library functions.
To declare the main() function.
To enable object-oriented programming.
The #include directive brings in declarations for standard input/output functions such as printf and scanf. Without this header, these functions may not be recognized by the compiler.
How do you declare an integer variable named 'num' in C?
var num;
int num;
integer num;
num: int;
In C, the keyword 'int' is used to declare integer variables. The other options reflect syntax from other programming languages or are outright invalid in C.
Which symbol correctly terminates a statement in C?
Period (.)
Colon (:)
Semicolon (;)
Comma (,)
In C, the semicolon is used to terminate statements. The other punctuation marks do not serve this purpose and are used in different contexts.
Which operator is used for multiplication in C?
*
#
x
%
The asterisk (*) is the multiplication operator in C. The other symbols are either not operators or serve different functions, such as modulus (%) or preprocessor directives (#).
Which looping structure is most appropriate when the number of iterations is known beforehand?
while loop
infinite loop
for loop
do-while loop
A for loop is specifically designed for scenarios where the number of iterations is predetermined. While and do-while loops are generally used when the number of iterations is uncertain.
What does the statement 'return 0;' signify when used at the end of the main() function in C?
It pauses the program.
It indicates that the program executed successfully.
It restarts the program.
It ends the program with an error.
Returning 0 from the main() function is a convention in C that signifies successful program termination. Other non-zero values are often used to indicate different error states.
What is the output of the following code snippet? for(int i = 0; i < 3; i++) { printf("%d", i); }
123
321
012
0 1 2
The loop starts with i=0 and iterates until i is less than 3, printing 0, 1, and 2 consecutively without spaces. Therefore, the printed output is "012".
What is the primary purpose of the 'break' statement in a loop in C?
To exit the loop immediately.
To pause the loop temporarily.
To restart the loop.
To skip the current iteration.
The break statement is used to terminate the loop immediately when a certain condition is met. It does not merely skip an iteration or pause the loop.
Which of the following is a correct function prototype for a function that returns a float and accepts an integer parameter?
functionName float(int);
float functionName();
functionName(int): float;
float functionName(int);
The correct function prototype first specifies the return type followed by the function name and the type of its parameters in parentheses. Option A follows the proper C syntax.
What does the 'const' keyword indicate when used in a variable declaration in C?
The variable is automatically global.
The variable must be declared outside any function.
The variable's value cannot be modified after initialization.
The variable is stored in constant memory.
The const keyword is used to declare that a variable's value should not change after its initial assignment. It enforces immutability and helps prevent accidental modifications.
How do you properly declare and initialize an array of ten integers in C?
int arr(10) = {0};
int arr[10] = {0};
int arr[10] = (0);
array arr[10] = {0};
In C, an array is declared by specifying the data type, the array name, and its size within square brackets. The initializer {0} sets the first element to 0, and many compilers will default the remaining elements to 0 as well.
Which format specifier and argument should be used with scanf() to read a string (character array) in C?
%c with the ampersand (&) before the variable name
%f without the ampersand (&) before the variable name
%s without the ampersand (&) before the variable name
%d with the ampersand (&) before the variable name
When reading a string into a character array using scanf, the %s format specifier is used and the array name is passed without the ampersand because it already acts as a pointer. Other specifiers correspond to integers, floats, or single characters.
Which of the following is NOT a valid storage class specifier in C?
static
inherit
auto
extern
The valid storage class specifiers in C are auto, static, extern, and register. 'inherit' is not recognized as a storage class specifier in C.
What does the pre-increment operator (++i) do in C?
Increments the value of i before it is used in an expression.
Decrements the value of i before it is used in an expression.
Declares a new variable i and initializes it to 1.
Increments the value of i after it is used in an expression.
The pre-increment operator (++i) increases the value of i before its value is used in any further operations within the expression. In contrast, the post-increment operator (i++) uses the current value before incrementing.
Which of the following statements correctly allocates memory for an array of 10 integers using malloc in C?
int arr = malloc(10 * sizeof(int));
int* arr = malloc(10);
int *arr = (int*)malloc(10 * sizeof(int));
int *arr = (int*)calloc(10, sizeof(int));
Option A correctly allocates memory for 10 integers by multiplying 10 with sizeof(int) and casting the returned pointer appropriately. The other options either misuse malloc or use a different memory allocation function.
If p is a pointer to an int in C, what does the expression p++ do?
Increments the integer value pointed by p.
Moves the pointer to point to the next integer in memory.
Moves the pointer to the next byte in memory.
Causes a compilation error.
In C, pointer arithmetic is scaled by the size of the data type pointed to. Therefore, p++ moves the pointer ahead by sizeof(int) bytes, pointing to the next integer element.
What is the primary purpose of using malloc() in C programming?
To free allocated memory once it is no longer needed.
To allocate memory dynamically during runtime.
To initialize static arrays.
To declare a pointer variable.
malloc() is used to allocate a block of memory dynamically at runtime, which allows for flexible use of memory. It does not free memory or declare pointers, and it is not used for static array initialization.
Which of the following best describes the use of a function pointer in C?
It is used to define recursive functions.
It points to a function's return type.
It allows a function to be stored in a variable and called indirectly.
It is used to store the memory address of an integer variable.
A function pointer holds the address of a function, enabling indirect calling of functions and facilitating callbacks. The other options do not accurately describe the function pointer's purpose.
What is a common cause of a segmentation fault in C programs?
Using too many global variables.
Including extra header files.
Declaring variables inside a loop.
Dereferencing a NULL or uninitialized pointer.
Segmentation faults typically occur when a program tries to access memory it is not allowed to, such as by dereferencing a NULL or uninitialized pointer. The other options do not usually lead to a segmentation fault.
0
{"name":"Which of the following is the correct syntax to print \"Hello, World!\" in C?", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"Which of the following is the correct syntax to print \"Hello, World!\" in C?, What is the purpose of the #include directive in a C program?, How do you declare an integer variable named 'num' in C?","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}

Study Outcomes

  1. Understand and apply fundamental C programming syntax and structure.
  2. Analyze common coding errors and debug C programs effectively.
  3. Apply algorithmic problem-solving techniques using C.
  4. Evaluate code efficiency and optimize C program performance.
  5. Interpret and implement exam-style exercises to enhance test readiness.

Online C Practice Test Cheat Sheet

  1. Understand C's Data Types - Dive into the building blocks of C by learning how int, float, char, and double store values in memory. Grasping each type's size and precision helps you write efficient code and avoid nasty surprises like overflow or rounding errors. Experiment with different types to see how they behave under the hood! 10 Concepts Every C Programmer Should Know
  2. Master Control Structures - Loops and conditionals are your toolkit for sculpting program flow in C. Use for, while, and do-while loops to repeat tasks, and if, else, and switch to make decisions based on dynamic data. With these constructs under your belt, you'll turn static code into interactive, responsive programs. 10 Concepts Every C Programmer Should Know
  3. Utilize Functions for Modularity - Break your code into bite‑sized, reusable chunks with functions that accept parameters and return values. Modular design boosts readability, makes testing easier, and helps you avoid copy‑paste nightmares. Plus, well‑named functions serve as self‑documenting guides through your program! 10 Concepts Every C Programmer Should Know
  4. Grasp the Use of Pointers - Pointers are variables that hold memory addresses - your secret weapon for dynamic memory management and efficient array operations. Mastering pointers lets you manipulate data structures directly and unlock powerful techniques like pointer arithmetic. Once you "get" pointers, you'll see C's flexibility and performance advantages shine. GeeksforGeeks: C Data Structures
  5. Implement Arrays Effectively - Arrays let you store collections of values in contiguous memory, making bulk operations and indexed access lightning fast. Understand how to declare, initialize, and loop through arrays to handle lists of data without breaking a sweat. Combine them with pointers for even more powerful patterns! GeeksforGeeks: C Data Structures
  6. Explore Structures for Complex Data - Structures group variables of different types under one name, enabling you to model real‑world entities like students or products. With structs, you can build rich data types and even nest them to create complex, hierarchical records. They're the cornerstone of organized, maintainable C programs! GeeksforGeeks: C Data Structures
  7. Manage Memory Dynamically - Learn to allocate and release memory on the fly with malloc() and free(), giving your programs the flexibility to grow or shrink during execution. Proper dynamic memory management is crucial to avoid leaks and dangling pointers. Practice allocating arrays, structs, and custom types to see how memory flows through your code. GeeksforGeeks: C Data Structures
  8. Understand File Handling - Interact with the outside world by reading from and writing to files using fopen(), fclose(), fprintf(), and fscanf(). File I/O lets you preserve data between runs and process large datasets without cluttering your console. Mastering file streams opens up possibilities like logging, configuration files, and data persistence. GeeksforGeeks: C File Handling Tutorial
  9. Learn Preprocessor Directives - The C preprocessor runs before compilation and handles directives like #include and #define. Use #include to pull in headers and #define for constants or macros that simplify repeated code. Conditional compilation (#ifdef, #ifndef) is perfect for cross‑platform builds and debug versus release modes! GeeksforGeeks: C Preprocessor Guide
  10. Practice Error Handling - Don't let runtime errors crash your program - use functions like perror() and strerror() to catch and report issues gracefully. Check return values from system calls and library functions to ensure robust, predictable behavior. Building good error‑handling habits will make your code rock‑solid and easier to debug. GeeksforGeeks: C Error Handling Techniques
Powered by: Quiz Maker