10 Technical Interview and Aptitude Questions: Set 6 (Solved)
Solved Set 6: arrays vs lists, OOP pillars, macros vs functions, Floyd's cycle detection, and swap-without-temp in C, ten questions campus drives test.
Set 6 adds ten more solved questions campus drives test routinely: arrays vs lists, OOP pillars, macros vs functions, and Floyd’s cycle detection algorithm in C.
If you worked through Set 4, you saw pointer arithmetic, SQL basics, and FCFS scheduling. This set shifts into data structure comparisons, core OOP, and classic C algorithms. The format stays the same: one question, the correct answer, and the reasoning you’d need to explain it in a 20-minute technical round.
For a broader list of concepts that appear repeatedly across campus drives, the must-know technical questions reference covers 18 topics across DSA, OS, DBMS, OOP, and networking.
Data Structures
Q1: What is the difference between an array and a list?
- Array: stores elements of the same data type (homogeneous); uses static, contiguous memory allocation; allows direct access to any element by index in O(1) time.
- List (linked list): stores elements of the same or different types; uses dynamic, non-contiguous memory allocation (nodes connected by pointers); requires sequential traversal to reach an element, so access is O(n) in the worst case.
The key trade-off: arrays give you fast random access but fixed size; linked lists give you dynamic size but sequential access.
Q2: What are the differences between a structure and an array?
| Property | Array | Structure |
|---|---|---|
| Data types stored | One (homogeneous) | Multiple (heterogeneous) |
| Element access | By index: arr[2] | By field name: s.age |
| Size | Fixed at declaration | Fixed, but fields can be different sizes |
| Use case | Sequence of like items | Grouped record of unlike fields |
An array of int cannot hold a float alongside it. A struct Student can hold name (char array), roll_no (int), and cgpa (float) in one unit.
Q3: What is a data structure?
A data structure is an organised way to store, retrieve, and modify data so that operations on it are efficient. The choice of data structure determines the time and space complexity of every operation a program performs on that data.
Common data structures include arrays, linked lists, stacks, queues, trees, graphs, and hash tables.
Q4: Where are data structures extensively used?
Data structures underlie nearly every systems-level component:
- Compiler design: symbol tables use hash maps; expression parsing uses stacks.
- Operating systems: the ready queue and wait queue are linked lists or priority queues; page tables are arrays.
- Database management systems: B-trees and B+ trees are the standard index structures.
- Graphics and multimedia: spatial trees (octrees, k-d trees) accelerate scene rendering and collision detection.
- Statistical analysis packages: matrix operations on two-dimensional arrays are the foundation of every numerical library.
Object-Oriented Programming
Q5: What are the advantages of inheritance?
- Code reuse: a child class inherits all non-private methods and fields from the parent, so you don’t rewrite logic that already works.
- Hierarchical modelling: parent → child relationships map naturally to real-world hierarchies (Animal → Mammal → Dog).
- Method overriding: the child can specialise inherited behaviour without changing the parent class, keeping the codebase open for extension.
- Reduced test surface: code in the base class is already tested; derived classes only need tests for what they override or add.
Q8: What are the four basics of Object-Oriented Programming?
- Encapsulation: data and the methods that operate on it are bundled into one unit (the class). Access modifiers (
private,protected,public) control what the outside world can see. This is why a class field is typicallyprivatewith a public getter/setter. - Inheritance: a class acquires the properties and behaviour of another class. Code written in the parent class is available to all child classes without repetition.
- Polymorphism: one interface, multiple implementations. Method overloading is compile-time polymorphism (same name, different parameters); method overriding is run-time polymorphism (parent reference calls the child’s version at runtime).
- Abstraction: hide implementation details and expose only what the caller needs. Interfaces and abstract classes are the standard tool; the caller knows what an operation does, not how.
Abstraction is the concept that makes blockchain technology fundamentals readable at a protocol level: a node caller does not need to know the consensus mechanism internals to submit a transaction.
C Programming Fundamentals
Q6: What are the advantages of a macro over a function?
- No function-call overhead: macros expand at compile time, so no stack frame is pushed, no return address is saved, and no jump instruction is executed. For operations called millions of times in a loop, this is measurable.
- Type-agnostic: a macro like
#define MAX(a, b) ((a) > (b) ? (a) : (b))works onint,float, ordoublewithout overloads. - Conditional compilation:
#ifdef/#ifndefguards control which code the compiler even sees, which is the standard mechanism for platform-specific code and header guards.
The downside is that macros have no scope, no type safety, and debugging them is harder because the preprocessor substitutes text blindly. Modern C++ prefers inline functions or templates for the same performance goals.
Q7: What is a command-line argument?
A command-line argument is a value passed to a program when it is invoked from the terminal, before the first line of main() executes. The standard signature of main() that accepts them is documented in cppreference.com main function reference:
int main(int argc, char *argv[])
argc(argument count): integer holding the number of arguments, including the program name itself, so it is always>= 1.argv[](argument vector): array of character pointers;argv[0]is the program name,argv[1]onwards are the values the user typed.- An optional third parameter
envp[]holds the environment variable strings.
For example, running ./program hello world gives argc = 3, argv[0] = "./program", argv[1] = "hello", argv[2] = "world".
Algorithms in C
Q9: How do you check whether a linked list is circular?
Use Floyd’s cycle detection algorithm: two pointers that traverse the list at different speeds. GeeksforGeeks covers this in detail with complexity analysis; here is the core logic:
#include <stdio.h>
struct Node {
int data;
struct Node *next;
};
void checkCircular(struct Node *head) {
struct Node *slow = head;
struct Node *fast = head;
while (fast != NULL && fast->next != NULL) {
slow = slow->next;
fast = fast->next->next;
if (slow == fast) {
printf("The list is circular\n");
return;
}
}
printf("The list is not circular\n");
}
slowadvances one node per iteration;fastadvances two.- In a circular list,
fastlapsslow— they will point to the same node after at most n iterations (where n is the list length). - In a linear list,
fast(orfast->next) reachesNULL, and the loop exits without the pointers ever meeting. - Time complexity: O(n). Space complexity: O(1) — no extra data structure needed.
For more technical interview questions from product companies that test this kind of algorithmic thinking, see the Cadence technical interview questions guide.
Q10: Write a program to swap two numbers without using a temporary variable.
#include <stdio.h>
void swap(int *x, int *y) {
*x = *x + *y; /* x holds the sum */
*y = *x - *y; /* recover original x */
*x = *x - *y; /* recover original y */
}
int main(void) {
int a = 5, b = 10;
swap(&a, &b);
printf("After swap: a = %d, b = %d\n", a, b);
return 0;
}
Verification step by step:
- Start:
a = 5,b = 10 - After
*x = *x + *y:a = 15,b = 10 - After
*y = *x - *y:b = 15 - 10 = 5,a = 15 - After
*x = *x - *y:a = 15 - 5 = 10,b = 5 - Result:
a = 10,b = 5— correct swap verified.
One caution: if a + b exceeds INT_MAX for 32-bit signed integers, the addition overflows and the behaviour is undefined in C. The XOR method (a ^= b; b ^= a; a ^= b) is overflow-safe but fails if x and y point to the same memory location (both become zero).
The ten questions above span the four areas (data structures, OOP, C fundamentals, and algorithms) that campus technical screens draw from most consistently. Knowing why Floyd’s algorithm works (not just what it does) and being able to trace the arithmetic swap step by step are exactly the kinds of verification skills interviewers probe when they ask you to “explain your reasoning.”
Those same verification skills transfer directly to working with AI code generation tools. When an LLM produces a linked-list cycle checker or a swap function, being able to trace through it and spot an off-by-one or an overflow hazard is what separates a developer who uses AI from one who is supervised by it. TinkerLLM at ₹299 is the practical entry point, a sandbox where you debug, extend, and verify AI-generated C and Python code rather than passively read it.
Primary sources
Frequently asked questions
What topics does Set 6 cover?
Arrays vs lists, structures vs arrays, data structure applications, the four OOP pillars, inheritance advantages, macros vs functions, command-line arguments, Floyd's cycle detection, and swap-without-temp in C.
How does Floyd's two-pointer algorithm detect a circular linked list?
A slow pointer moves one node at a time; a fast pointer moves two. In a circular list, fast eventually laps slow and they point to the same node. If fast reaches NULL, the list is linear.
When does swapping integers without a temporary variable fail in C?
The arithmetic method (a = a+b; b = a-b; a = a-b) causes undefined behaviour if a+b overflows a signed int. The XOR method (a^=b; b^=a; a^=b) avoids overflow but produces the wrong result if both pointers alias the same memory location.
What is the main advantage of a macro over a function in C?
Macros expand inline at compile time, so there is no function-call overhead — no stack frame push, no return-address save. For small operations called in tight loops this avoids measurable cost, though modern compilers often inline small functions automatically.
Which OOP pillar is tested most often in campus technical rounds?
Polymorphism and encapsulation appear in the majority of campus screens. Polymorphism questions ask to distinguish method overloading (compile-time) from method overriding (run-time); encapsulation questions focus on access modifiers and data hiding.
Do Set 6 topics appear in TCS NQT or Infosys InfyTQ?
Yes. OOP pillars, data structure definitions, and basic C programming (macros, command-line arguments) are standard topics in TCS NQT Technical, Infosys InfyTQ, Wipro NLTH, and Cognizant GenC technical rounds.
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)