Font size
WorksheetsC Programming Quiz
Total questions: 80
Worksheet time: 53mins
What is the output of
` printf("%d", 5 + 2 * 3); `?
21
11
16
15
Which function returns the length of a string?
strcopy()
strlen()
strcmp()
strcat()
Which of the following is a valid C identifier?
int@num
123abc
_varName
void
What does `#include
Declares main function
Links standard I/O functions
Allocates memory
None of the above
What is the output of the following loop? for(int i = 0; i < 3; i++) { printf("%d ", i); }
0 1 2
1 2 3
0 1 2 3
0 1
Which storage class maintains the variable value between function calls?
auto
register
static
extern
Which operator is used to access the value at an address in C?
&
*
->
@
How many bytes will this union occupy in memory?
union u1 { int a; float b; };
0
4
8
2
In C, what is the index of the first element in an array?
1
0
-1
Depends on declaration
Which bitwise operator is used to shift bits to the left?
<<
>>
&
~
Which loop is guaranteed to execute at least once in C?
for
while
do-while
nested if
Which function is used to open a file?
open()
fopen()
startfile()
read()
Pseudocode output: sum = 0 for i = 1 to 3: sum = sum + i print sum
6
3
9
5
What does `strcpy()` function do?
Appends strings
Compares strings
Copies one string into another
Calculates length
Which of the following is a character constant?
"A"
'A'
A
"65"
What is the output of
`printf("%d", a++);`
if int a = 5?
5
6
4
Error
Which symbol is used for decision in a flowchart?
Rectangle
Parallelogram
Diamond
Circle
What is recursion in C?
Looping structure
Function calling itself
Infinite loop
Memory allocation
What is used to prevent memory leaks in C?
free()
malloc()
calloc()
memcpy()
Which keyword is used to define integer variable in C?
float
double
int
var
What is the result of `4 << 1`?
2
8
1
6
Which of the following is used to declare a structure in C?
union
class
struct
object
What is the role of `#define`?
Include file
Compile conditionally
Create macro
Debug
Which of the following is a string literal?
'abc'
"abc"
abc
[abc]
What is the output of: int x = 10;
if (x > 5) {
if (x < 15)
printf("A");
else printf("B");
}
else {
printf("C");
}
A
B
C
AB
Which function is used to close a file?
endfile()
fclose()
stopfile()
closefile()
What is the correct format specifier for printing a float value?
%d
%c
%f
%s
What is a mask in bitwise operation?
Input method
Special operator
Filter applied on bits
Debugging mode
In a 2D array declared as `int arr[3][2];`, how many elements are there?
5
6
3
2
What does `strcmp()` return if both strings are equal?
1
-1
0
Error
Which of these sorts arrays?
intsort()
bubblesort()
quicksort()
sort()
What is the output of: int arr[] = {1, 2, 3}; printf("%d", arr[1]);
1
2
3
4
What is a segmentation fault?
Infinite loop
Hardware error
Invalid memory access
File error
What is the result of: int a = 5;
int *p = &a; printf("%d", *p);
5
Address of a
Error
0
Which of the following is NOT a loop control statement?
while
if
for
do
What is the purpose of `exit(0);`?
Exit from loop
Exit from block
Exit program
End recursion
What is `malloc()` used for?
Static memory allocation
Dynamic memory allocation
File handling
None
What is the output of:
int fun() {
static int x = 0; x++;
return x;
}
main() {
printf("%d", fun());
printf("%d", fun());
}
11
12
22
01
What is `void` used for in functions?
What is `void` used for in functions?
To declare integer type
To indicate function returns nothing
For memory access
To free memory
What does `feof()` return at end of file?
-1
0
1
NULL
Which format specifier is used to print a single character?
%d
%s
%f
%c
What is the output of this pseudocode? void swap(int x, int y) {
int temp = *x;
x = y;
*y = temp;
}
int main() {
int a = 10;
int b = 20;
swap(&a, &b);
printf("%d %d\n", a, b);
return 0;
10 20
20 10
Error
Undefined
What will `sizeof(char)` return?
1
2
4
8
What is the keyword used to define a constant value in C?
const
static
final
define
In memory representation, how are 2D arrays stored?
Column major
Random access
Row major
Diagonal
Which is true about function declaration?
Optional in C
Mandatory before main
Always ends with return
Never ends with semicolon
What is the default value of an uninitialized local variable?
0
Garbage
NULL
-1
Which of the following is used to comment in C?
// or /* */
# comment
--
Which operator has the highest precedence in C?
*
++
=
&&
What is the result of the expression `5 % 2`?
1
2
0
2.5
Which keyword is used for calling by reference in C?
&
*
->
None (C uses pointers instead)
In a structure, how are members accessed?
. (dot operator)
->
&
*
Which of the following is used to read a character from the keyboard?
getch()
scanf()
getchar()
Both a and c
What will `strcmp("abc", "abd")` return?
0
1
Negative value
Positive value
What is time complexity of printing first n natural numbers?
O(n^2)
O(1)
O(n)
O(log n)
Which file mode is used to read a file in binary mode?
"r"
"rb"
"b"
"br"
What is the role of `fseek()`?
Read file
Write file
Move file pointer
Close file
Which loop is used when the number of iterations is known?
for
while
do-while
switch
What is the output of:
int a = 4, b = 2;
printf("%d", a & b);
0
2
4
6
Which algorithm is based on Divide & Conquer?
Bubble sort
Quick sort
Linear search
Insertion sort
What is the result of the following pseudocode?
int main() {
int n = 3;
int fact = 1;
for (int i = 1; i <= n; i++) {
fact = fact * i;
}
printf("%d\n", fact);
3
6
5
9
Which header file is needed for string functions?
stdlib.h
conio.h
string.h
stdio.h
Which of the following is **not** a valid keyword in C?
return
continue
start
goto
What is `&a` in C?
Address of a
Value of a
Reference to a
Pointer
What happens if you forget to close a file?
Compiler error
Memory leak
Nothing
File corruption
Which pointer type can store address of any variable?
int *
char *
float *
void *
What will be the output of:
int a = 3;
printf("%d", a == 3 ? 5 : 10);
3
5
10
Error
What does `continue;` do inside a loop?
Ends loop
Restarts program
Skips current iteration
Reverses loop
Which operator is used to compare equality?
=
==
!=
:=
What will be the output of the following code?
int a[5] = {1, 2, 3, 4, 5};
printf("%d", *(a + 3));
2
3
4
5
What does the following code snippet do?
int a = 10, b = 20;
int p = &a, q = &b;
int temp = *p;
p = q;
*q = temp;
Swaps the values of a and b
Assigns value of b to a only
Assigns value of a to b only
Does nothing
What will be the result of the following queue code?
int queue[5] = {1, 2, 3, 4, 5};
int front = 0, rear = 4;
printf("%d", queue[front++]);
1
2
5
Compilation Error
What is the output of the following binary search code?
int arr[] = {1, 3, 5, 7, 9}, key = 5;
int low = 0, high = 4;
while (low <= high) {
int mid = (low + high) / 2;
if (arr[mid] == key) {
printf("%d", mid);
break;
} else if (arr[mid] < key) low = mid + 1;
else high = mid - 1;
}
0
1
2
3
What is the time complexity of this recursive function?
void recur(int n) {
if (n <= 1) return;
recur(n/2);
recur(n/2);
}
O(n)
O(log n)
O(n log n)
O(n)
What is printed by this linked list traversal code?
struct Node {
int data;
struct Node* next;
};
struct Node n3 = {30, NULL};
struct Node n2 = {20, &n3};
struct Node n1 = {10, &n2};
struct Node* ptr = &n1;
while (ptr != NULL) {
printf("%d ", ptr->data);
ptr = ptr->next;
}
10 20 30
30 20 10
10 30
Segmentation fault
Which operation causes overflow in a stack (array implementation)?
if (top == MAX - 1) {
printf("Overflow");
}
Pushing when top is -1
Popping when top is 0
Pushing when top == MAX - 1
Popping when top > 0
What will be the output of this tree traversal?
(Given a BST with values inserted in order: 5, 3, 7, 2, 4)
// In-order traversal
void inorder(struct Node* root) {
if (root != NULL) {
inorder(root->left);
printf("%d ", root->data);
inorder(root->right);
}
}
5 3 7 2 4
2 3 4 5 7
7 5 4 3 2
2 4 3 5 7
What will be the output of the following C code involving a singly linked list?
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
void printList(struct Node* head) {
while (head) {
printf("%d ", head->data);
head = head->next->next;
}
}
int main() {
struct Node* head = malloc(sizeof(struct Node));
head->data = 1;
head->next = malloc(sizeof(struct Node));
head->next->data = 2;
head->next->next = malloc(sizeof(struct Node));
head->next->next->data = 3;
head->next->next->next = NULL;
printList(head);
return 0;
}
1 2 3
1 3
1
Segmentation Fault
