10 Technical Interview and Aptitude Questions: Set 4
Ten solved questions on C pointer arithmetic, double pointers, scanf bugs, linked-list traversal, binary search, SQL filtering, first normal form, and FCFS scheduling.
The ten questions in Set 4 cover C pointer arithmetic, double pointers, linked-list traversal, binary search, SQL filtering, first normal form, and FCFS scheduling, all drawn from the technical rounds of campus placement drives.
This set follows Set 1 and Part 2 of this series. Set 3, Set 5, and Set 6 are not yet published. For Java-specific technical rounds, most asked Java interview questions is a useful companion.
C Programming: Pointers and Memory
Pointer questions appear in the technical coding section of most campus placements. The reason is practical: tracing pointer behaviour without running the code reliably distinguishes candidates who understand execution from those who guess.
Q1: Pointer Increment and Dereference
#include <stdio.h>
int main() {
int arr[] = {10, 20, 30};
int *p = arr;
p++;
printf("%d\n", *p);
return 0;
}
- Answer:
20 - Step 1:
int *p = arrsetspto point atarr[0], which holds10. - Step 2:
p++advances the pointer bysizeof(int)bytes. On a 32-bit int system, that is 4 bytes.pnow points atarr[1]. - Step 3:
*pdereferences the pointer and readsarr[1], which is20. - Key rule: Adding 1 to a typed pointer moves it forward by the size of the element type, not by 1 byte. Reference: C pointers — cppreference.com.
Q2: The Missing & in scanf
int num;
scanf("%d", num);
What is wrong with this statement?
- Bug: Missing
&beforenum. - What happens: Without
&,scanfreceives the current value ofnum(indeterminate at declaration) as a memory address. It tries to write the entered integer to that invalid address, causing undefined behaviour. The typical outcome is a segmentation fault or a silent wrong write to an unrelated memory location. - Fix:
scanf("%d", &num);passes the address ofnumsoscanfcan write the entered integer to the correct location. - Why it appears in interviews: This is the single most common C input bug in placement paper code-correction sections.
Q3: The %10.2f Format Specifier
What does printf("%10.2f", 3.14159); print?
- Answer:
3.14(six leading spaces, then3.14) 10field width: Reserve 10 characters for the output. Numbers are right-aligned by default..2precision: Round to 2 decimal places.3.14159rounds to3.14.- Character count:
"3.14"is 4 characters. Padded to fill 10 characters gives 6 leading spaces followed by3.14. - Edge case: If the number is wider than the field (for example,
printf("%5.2f", 12345.6)), the field width is overridden and the full number is printed.
Q4: Double Pointer Output Prediction
#include <stdio.h>
int main() {
int x = 5;
int *p = &x;
int **q = &p;
**q = 15;
printf("%d\n", x);
return 0;
}
- Answer:
15 - Step 1:
pholds the address ofx. - Step 2:
qholds the address ofp.qis a pointer to a pointer to int. - Step 3:
*qdereferencesqto getp.**qdereferences again to reachx. - Step 4:
**q = 15writes15directly intox. - Verify: After the assignment,
x == 15. Theprintfconfirms15.
Data Structures: Trace the Output
The two questions here test whether you can walk through a function call with a concrete data structure and arrive at the correct return value before checking it in an IDE.
Q5: Linked-List Node Count
struct Node {
int data;
struct Node *next;
};
int countNodes(struct Node *head) {
int count = 0;
while (head != NULL) {
count++;
head = head->next;
}
return count;
}
The list passed in is 3 -> 7 -> 1 -> NULL. What does countNodes(head) return?
- Answer:
3 - Iteration 1:
headpoints to node with data3(not NULL).countbecomes1.headadvances to node7. - Iteration 2:
headpoints to node7.countbecomes2.headadvances to node1. - Iteration 3:
headpoints to node1.countbecomes3.headbecomesNULL. - Loop exits:
head == NULL. Function returns3.
For practice on algorithmic string problems that also require step-by-step tracing, see remove brackets from an algebraic expression.
Q6: Binary Search Return Value
int binarySearch(int arr[], int l, int r, int x) {
while (l <= r) {
int mid = l + (r - l) / 2;
if (arr[mid] == x) return mid;
if (arr[mid] < x) l = mid + 1;
else r = mid - 1;
}
return -1;
}
Call: binarySearch(arr, 0, 4, 7) on arr = {1, 3, 5, 7, 9}. What does the function return?
- Answer:
3(the index of7inarr) - Round 1:
l=0,r=4,mid=2.arr[2]=5.5 < 7, sol = mid + 1 = 3. - Round 2:
l=3,r=4,mid=3.arr[3]=7.7 == 7. Return3. - Why
mid = l + (r - l) / 2: This avoids integer overflow that(l + r) / 2can cause whenlandrare both large. A subtle correctness detail that interviewers notice.
DBMS and SQL Fundamentals
SQL output-prediction and normalization questions appear in the technical rounds of most large service companies. Knowing the sequence in which SQL clauses execute (FROM, WHERE, SELECT, ORDER BY) makes these questions straightforward.
Q7: SQL SELECT with WHERE and ORDER BY
Table Students:
| id | name | marks |
|---|---|---|
| 1 | Ananya | 82 |
| 2 | Ravi | 71 |
| 3 | Meena | 90 |
| 4 | Kabir | 68 |
SELECT name FROM Students WHERE marks > 75 ORDER BY marks DESC;
- Answer: Two rows returned:
Meena, thenAnanya. - Step 1 (WHERE): Only rows where
marks > 75pass the filter. Ananya (82) and Meena (90) qualify. Ravi (71) and Kabir (68) are excluded. - Step 2 (ORDER BY marks DESC): Of the two qualifying rows, Meena (90) is listed before Ananya (82).
- Output column: Only
nameis in the SELECT list. Values fromidandmarksare not returned, even thoughmarkswas used in the filter and sort.
Q8: First Normal Form (1NF) Violation
Consider this table:
| emp_id | name | skills |
|---|---|---|
| 101 | Priya | Java, Python, C++ |
| 102 | Arjun | SQL, MongoDB |
Does this table satisfy first normal form?
- Answer: No. It violates 1NF.
- The rule: First normal form requires every cell to hold an atomic (indivisible) value.
- The violation: The
skillscolumn stores a comma-separated list. Each row has multiple skill values in a single cell. - The fix: Decompose into a separate table with one row per skill per employee:
(emp_id, name, skill). Priya gets three rows; Arjun gets two. - Why it matters: Tables that violate 1NF cause UPDATE anomalies, make indexing on individual skill values impossible, and complicate every query that needs to filter by skill.
Operating System Basics
OS questions in campus technical rounds typically focus on scheduling algorithms, process states, and the process-thread distinction.
Q9: FCFS Scheduling and Average Waiting Time
Three processes arrive at time 0 and run in FCFS order:
| Process | Burst Time |
|---|---|
| P1 | 4 ms |
| P2 | 2 ms |
| P3 | 6 ms |
- Execution order: P1 runs first (0–4 ms), then P2 (4–6 ms), then P3 (6–12 ms).
- Waiting time P1:
0 ms(starts immediately at time 0). - Waiting time P2:
4 ms(P2 waits for P1 to finish). - Waiting time P3:
4 + 2 = 6 ms(P3 waits for both P1 and P2). - Average waiting time:
(0 + 4 + 6) / 3 = 10 / 3 = 3.33 ms.
For worked examples with other scheduling algorithms (SJF, Round Robin), see GeeksforGeeks: FCFS CPU Scheduling.
Q10: Process vs. Thread
What are the key differences between a process and a thread?
- Process: An independent execution unit with its own virtual address space, file handles, and system resources. The OS treats each process as isolated.
- Thread: A lightweight execution unit inside a process. Threads within the same process share the address space, heap, and open file descriptors.
- Creation cost: Spawning a new process (fork) is expensive because the OS must allocate a new address space. Creating a thread is cheaper because it reuses the parent process’s resources.
- Communication: Processes exchange data through IPC (pipes, sockets, shared memory segments). Threads within the same process communicate through shared variables in the common address space.
- Crash isolation: A crash in one process does not affect other processes. A crash in one thread can terminate the entire process, because all threads share the same address space.
- Exam follow-up: “Which has lower context-switch overhead?” Answer: threads, because switching threads within the same process does not require changing the memory-address mapping.
How to Use This Set in Placement Prep
Each of the ten questions above tests one habit: trace what the program or query does, step by step, before confirming. The pointer arithmetic and binary search traces reward exactly that. So does the SQL filter: walk the WHERE clause mentally, then apply the ORDER BY, and you have the output. For most commonly asked Java interview questions that include output-prediction on inheritance and method overloading, the trace-first habit carries over directly.
That same discipline transfers to working with LLMs. When a prompt returns an unexpected output, the debugging loop is structurally the same: identify the input, trace what the model was attending to, compare expected against actual. TinkerLLM (₹299 entry point) gives you a scratchpad for that kind of structured experimentation with real LLM calls, where changing one variable in a prompt and observing the delta is the same loop as tracing a pointer dereference or a SQL filter chain.
Primary sources
Frequently asked questions
What topics does Set 4 cover?
Set 4 covers C pointer arithmetic, double pointers, the scanf missing-& bug, printf format specifiers, linked-list traversal, binary search, SQL SELECT with WHERE and ORDER BY, first normal form (1NF), FCFS scheduling, and the process-vs-thread distinction.
Do I need to know C to answer technical aptitude questions in campus placements?
For most campus drives, yes. TCS NQT, Infosys InfyTQ, Wipro NLTH, and Cognizant GenC all include a section where pointer and output-prediction questions appear. Understanding pointer arithmetic and storage classes is expected at the fresher level.
How is DBMS tested in campus technical rounds?
Typically through SQL query output prediction (SELECT, WHERE, ORDER BY, GROUP BY), normalization identification (1NF/2NF/3NF), keys and constraints, and basic ER diagram interpretation. Short scenario questions like 'does this table satisfy 1NF?' are common.
What is the difference between a process and a thread in an OS interview?
A process is an independent execution unit with its own address space. A thread is a lightweight unit within a process that shares the same address space. Thread creation is cheaper; inter-thread communication uses shared memory rather than IPC mechanisms like pipes or sockets.
How should I approach output-prediction questions in technical interviews?
Trace the code line by line on paper. Track variable values and pointer addresses at each step. For pointer questions, draw boxes for variables and arrows for addresses. For loops, annotate the loop variable on each iteration before reading the final printf line.
A self-paced playground for building with LLMs.
TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.
Try TinkerLLM (₹299 launch)