In C, this operator performs a bitwise AND between two integers.
Extra points for truth table!
What is &?
In a singly linked list, each node typically contains two parts. What are they?
What are the data field and the pointer to the next node?
What is that after calling free(curr), accessing curr->next is invalid because curr's memory has already been deallocated (use after free)?
What is two (left and right)?
What is printed by this code?
int x = 5;
printf("%d\n", x++);
What is 5?
What will this C code output?
int a = 6; // 0110
int b = 3; // 0011
printf("%d\n", a & b);
What is 2?
(Explanation: 0110 & 0011 = 0010 which is decimal 2.)
What's wrong here?
struct Node {
int data;
struct Node *next;
};
struct Node *head;
head->data = 10;
What is dereferencing an uninitialized pointer head?
(Explanation: head needs memory allocated, e.g., malloc, before dereferencing.)
What order does this traversal function perform?
void traverse(struct Node *root) {
if (root == NULL) return;
printf("%d ", root->data);
traverse(root->left);
traverse(root->right);
}
What is preorder traversal?
(Visit current node → left → right.)
In C, what does the %p format specifier print in printf?
What is a memory address (a pointer value)?
struct {
unsigned int x : 3;
} data;
What is 7?
(Explanation: 3 bits can represent values 0–7.)
In a singly linked list, what condition indicates you have reached the end of the list during traversal?
What is when the next pointer is NULL?
What mistake does this C function make when trying to insert into a binary tree?
void insert(struct Node *root, int val) {
if (root == NULL) {
root = malloc(sizeof(struct Node));
root->data = val;
root->left = root->right = NULL;
} else if (val < root->data) {
insert(root->left, val);
} else {
insert(root->right, val);
}
}
What is that setting root = malloc(...) only updates the local copy of the pointer — it does not update the parent's child pointer?
Fix:
The function must take a pointer to a pointer (struct Node **root) or return the new root.
In C, after calling malloc, you should always do this before using the returned pointer.
What is check if the pointer is NULL (to verify if memory allocation succeeded)?
Fix the logical error in this code:
if (flags & 0x02 == 0) {
printf("Flag 2 is not set.\n");
}
The bitwise AND has lower precedence than ==.
It should be:
if ((flags & 0x02) == 0) {
printf("Flag 2 is not set.\n");
}
What is wrong with this attempt to insert a new node at the head of a linked list?
struct Node *newNode = malloc(sizeof(struct Node));
newNode->data = 5;
newNode->next = head;
head = newNode->next;
What is that the last line should be head = newNode;, not newNode->next?
(Explanation: This code incorrectly moves head past newNode instead of pointing it to newNode.)
In a binary tree in C, when a node has both left == NULL and right == NULL, what is that node called?
What is a leaf node?
Which bitwise operator would you use to set specific bits without changing others?
What is bitwise OR (|)?
struct {
unsigned int flag : 1;
unsigned int mode : 2;
} settings;
What is the maximum decimal value that mode can hold?
What is 3?
You are given the following C code fragment to delete all nodes of a singly linked list:
struct Node *curr = head;
while (curr != NULL) {
free(curr);
curr = curr->next;
}
What is that after calling free(curr), accessing curr->next is invalid because curr's memory has already been deallocated (use after free)?
What order does this C function perform?
void traverse(struct Node *root) {
if (root == NULL) return;
traverse(root->left);
printf("%d ", root->data);
traverse(root->right);
}
What is inorder traversal?
(Visit left → current node → right.)
Given this struct:
struct Point {
int x;
int y;
};
struct Point *p = malloc(sizeof(struct Point));