WorksheetsPractice Quizz
Total questions: 60
Worksheet time: 30mins
What is a computer program?
A set of instructions for a computer to follow.
A type of hardware component.
A programming language.
A software application.
Which of the following is a valid C statement?
print "Hello, world!";
printf("Hello, world!\n");
echo "Hello, world!";
display "Hello, world!";
What is the purpose of a semicolon (;) in C?
To start a new line.
To end a statement.
To separate variables.
To comment out code.
What does the `%d` format specifier do in `printf()`?
Prints a floating-point number.
Prints a character.
Prints an integer.
Prints a string.
What does the `scanf()` function do?
Prints data to the console.
Reads data from the console.
Declares a variable.
Ends the program.
What does the `if` statement do in C?
Repeats a block of code.
Executes a block of code conditionally.
Declares a variable.
Defines a function.
What does the `for` loop do in C?
Executes a block of code repeatedly.
Executes a block of code conditionally.
Reads data from a file.
Writes data to a file.
What is a comment in C code?
A line of code that is executed.
A line of code that is ignored by the compiler.
A variable declaration.
A function definition.
How do you declare an integer variable named `count` in C?
int count;
integer count;
var count : int;
count = int;
Which of the following is a valid C identifier?
rollNumber 11
roll Number 3
rollNumber_9
65rollNumber
What is the size of a 'float' data type in C (in bytes)?
1
2
4
8
What will happen if you try to use an undeclared variable in your C program?
It will compile without errors.
It will give a compile-time error.
It will give a runtime error.
The program will crash.
Which keyword is used to stop a loop prematurely?
continue
break
both
none
What is the purpose of an assignment operator in C?
Performs arithmetic calculations
Compares two values
Assigns a value to a variable
Performs bitwise operations
What is the result of 10 % 3 in C?
3
3.33
1
0
Which relational operator checks for inequality?
==
!=
>=
<=
What does the logical AND operator (&&) return if both operands are true?
False
True
0
1
What is the bitwise AND operator?
&
|
^
~
What is the result of 5 & 3 (bitwise AND)?
8
1
7
0
What is the result of 5 ^ 3 (bitwise XOR)?
6
2
0
8
What is the bitwise NOT operator?
&
|
^
~
What is the result of ~5 (bitwise NOT, assuming 8-bit representation)?(this question requires calculation, keep in mind the 2's compliment representation while solving)
5
-6
10
-5
What is the precedence(priority) of arithmetic operators compared to assignment operators?
Arithmetic operators have lower precedence.
Assignment operators have lower precedence.
They have equal precedence.
It depends on the context.
What is the result of the expression x += 5; if x initially holds the value 10?
5
10
15
0
What is the result of the expression (10 > 5) || (5 > 10)?
0
1
-1
5
Which operator is used for bitwise XOR?
&
|
^
~
What is the result of (5 > 10) ? 1 : 0;
0
1
5
10
What does the ++ operator do?
Decrements a value by 1
Increments a value by 1
Multiplies by 2
Divides by 2
What is the result of !(1)?
0
1
-1
Error
What action does the following conditional statement perform? if (x = 5)
Checks if x equals 5
Assigns 5 to x and evaluates to true
Assigns 5 to x and evaluates to false
Generates a compiler error
Which statement correctly checks if a number is even in C?
if (number % 2 = 0)
if (number / 2 == 0)
if (number % 2 == 0)
if (number == 2)
What does a nested `if` statement do?
It creates an infinite loop
It allows an `if` statement within another `if` statement
It's a syntax error
It reverses the conditional logic
What does the `else if` statement do?
It allows multiple conditions to be checked sequentially.
It negates the previous `if` statement.
It is a syntax error.
It is equivalent to a nested `if` statement.
What data type is generally used in the `switch` statement's controlling expression?
float
double
char or integer
string
nt's controlling expression?
float
double
char or integer
string
Can a `case` label in a `switch` statement have a range of values?
Yes, using a dash to separate the start and end values.
Yes, using a comma to separate the values.
No, each `case` label must have a single value.
No, only string values are allowed.
What will happen if a `break` statement is omitted from a `case` in a `switch` statement?
The program will crash.
The next case will be executed.
The switch statement will be terminated.
It will compile but cause unpredictable behavior.
What is the purpose of a for loop?
To repeat a block of code indefinitely.
To execute a block of code a specific number of times.
To repeat a block of code until a condition is met.
To execute a block of code only once.
What is the difference between a `for` loop and a `while` loop?
A `for` loop is always faster.
A `while` loop can only iterate once.
A `for` loop is designed for a predetermined number of iterations.
A `while` loop always requires a counter variable.
Which loop guarantees at least one execution?
`for` loop
`while` loop
`do-while` loop
None of the above
A "do-while" loop checks the condition ________ the loop body.
Before
After
During
It doesn't check the condition
What does the "continue" statement do in a loop?
Exits the loop entirely.
Skips the current iteration and proceeds to the next.
Repeats the current iteration.
Stops the program execution.
Can you nest loops inside each other?
Yes
No
Only `for` loops can be nested.
Only `while` loops can be nested.
Can a `for` loop be used to iterate backwards?
Yes
No
What is the purpose of a counter variable in a loop?
To store the loop's condition.
To track the number of iterations.
To control the loop's exit condition.
To store the loop's body.
Which loop is generally preferred when the number of iterations is known beforehand?
`while` loop
`do-while` loop
`for` loop
It depends on the specific task
Is it possible to have a "for" loop with no initialization in syntax statement of for loop?
Yes
No
Is it possible to have a "for" loop with no condition?
Yes
No
How is an array declared in C?
int array = [10];
int array[10];
int array(10);
int array = {10};
What is the size of an array declared below? int numbers[5];
4 bytes
5 bytes
20 bytes (assuming int is 4 bytes)
5 * sizeof(int) bytes
What will happen if you try to access array[-1]` where `array` is an integer array?
The program compiles but crashes at runtime.
The program compiles and runs without any errors.
The compiler reports an error.
The last element of the array is accessed.
Are array elements automatically initialized to zero in C?
Yes, always
No, unless initialized
What's the output of this code snippet? int arr[5] = {1, 2, 3, 4}; printf("%d", arr[3]);
3
4
Garbage value
Compilation error
What is an advantage of using arrays?
Easy access to elements using their index
Dynamic resizing
Heterogeneous data storage
None of the above
Can an array be initialized at the time of its declaration?
Yes, using curly braces {}
No, initialization must be done separately.
Only if the array is globally declared.
Only if the array's size is known at compile time.
Which of the following is NOT a valid way to declare an array of 5 integers?
int arr[5];
int arr[5] = {0};
int arr[5] = {1, 2, 3, 4, 5, 6};
int arr[] = {1, 2, 3, 4, 5};
Which loop is can be used in the implementation of a linear search in C?
`for` loop
`while` loop
`do-while` loop
All of the above
What is the advantage of binary search over linear search?
Simpler implementation
Faster search time for large datasets
Works with unsorted data
Uses less memory
Binary search is more efficient than linear search when:
the data set is small
the data set is large and sorted
the data set is unsorted
the data set contains duplicates
In Bubble Sort, what is the purpose of the inner loop?
To divide the array into smaller subarrays
To compare and swap adjacent elements
To find the maximum element
To merge sorted subarrays
