1.
Recursion and Tail Recursion
Recursion is a programming technique where a function calls itself to solve smaller instances of a
problem. It's useful for problems like factorial, Fibonacci, and tree traversal. Tail recursion is a special
kind of recursion where the recursive call is the last operation in the function. Tail recursion is optimized
by compilers to avoid excessive stack usage. Example:
int factorial(int n, int result) {
if (n == 0) return result;
return factorial(n - 1, n * result);
}
2. Two Pointer Technique
The two-pointer technique involves using two indices to scan through a data structure, commonly used
in arrays and linked lists. It's useful for solving problems like pair sum, reversing arrays, and removing
duplicates efficiently. Example:
int i = 0, j = n - 1;
while (i < j) {
if (arr[i] + arr[j] == target) break;
else if (arr[i] + arr[j] < target) i++;
else j--;
}
3. Stack and Queue (LIFO, FIFO, Overflow, Underflow)
Stack and queue are abstract data types. Stack follows LIFO (Last In First Out), while Queue follows FIFO
(First In First Out). Overflow occurs when you try to add an element to a full structure, and underflow
occurs when you try to remove from an empty one. Example (Stack):
push(10); push(20); pop(); // Removes 20
Example (Queue):
enqueue(10); enqueue(20); dequeue(); // Removes 10
4. Structure and Union
Structures and unions are user-defined data types in C. Structures can store variables of different types,
each with separate memory. Unions also store variables of different types, but share the same memory
location, saving space. Example:
1
struct Person { int age; float height; };
union Data { int i; float f; };
5. 1D Array and 2D Array
A 1D array is a linear list of elements, while a 2D array is like a matrix or table of rows and columns.
Arrays store elements of the same type in contiguous memory locations. Example:
int a[5]; // 1D array
int b[3][3]; // 2D array
6. Base Address, Row and Column Major
The base address is the starting memory address of an array. In row-major order (used in C), array
elements are stored row-wise. In column-major order, used in some other languages, elements are
stored column-wise. Example (Row-major): a[2][3] stored as: a[0][0], a[0][1], a[0][2], a[1][0],...
7. Static and Dynamic Memory Allocation
Static memory allocation occurs at compile time, while dynamic memory allocation happens at runtime
using functions like malloc, calloc, realloc, and free. Example:
int a[10]; // Static
int *p = malloc(10 * sizeof(int)); // Dynamic
8. Linked List (Self-referential Structure, Advantages & Disadvantages)
A linked list is a data structure where each node contains data and a pointer to the next node. It uses
self-referential structures. Advantages: dynamic size, efficient insertion/deletion. Disadvantages: extra
memory for pointers, sequential access. Example:
struct Node {
int data;
struct Node* next;
};
9. calloc, malloc, realloc
• malloc allocates uninitialized memory.
• calloc allocates zero-initialized memory.
• realloc resizes previously allocated memory. Example:
int *p = malloc(5 * sizeof(int));
p = realloc(p, 10 * sizeof(int));
2
10. Flowchart and Algorithm
An algorithm is a finite step-by-step procedure to solve a problem. A flowchart is a visual representation
of an algorithm using symbols like arrows, ovals, and rectangles. Example (Steps): 1. Start 2. Input a, b
3. Sum = a + b 4. Output Sum 5. End
11. Compiler and Interpreter
A compiler translates the whole program into machine code before execution. An interpreter translates
and executes line by line. C uses compilers; Python uses interpreters. Example: C code needs to be
compiled with gcc or similar tools before execution.
12. Assembly Language and Translators
Assembly language uses mnemonics to represent machine instructions. Translators include compilers,
assemblers, and interpreters that convert high-level code into machine language. Example:
MOV AX, BX ; Assembly instruction
13. Preprocessor Directive
Preprocessor directives are instructions processed before compilation, starting with # . They handle
macro definitions, file inclusion, conditional compilation, etc. Example:
#include <stdio.h>
#define PI 3.14
14. Compilation of Code
The compilation process includes preprocessing, compiling, assembling, and linking. This converts
source code into an executable. Stages: 1. Preprocessing 2. Compilation 3. Assembly 4. Linking
15. Implicit and Explicit Type Casting
Implicit casting is automatic. Explicit casting uses the cast operator to convert one data type into
another manually. Example:
float a = 10; // Implicit
int b = (int)3.14; // Explicit
16. Entry and Exit Controlled Loop (while, do-while)
Entry-controlled loops (while) check condition before loop body. Exit-controlled loops (do-while) check
after execution, ensuring at least one execution. Example:
3
int i = 0;
do {
printf("%d", i);
i++;
} while(i < 3);
17. Break, Exit, Continue
• break exits loops or switch statements.
• continue skips current loop iteration.
• exit terminates the entire program. Example:
for (int i=0; i<5; i++) {
if (i==2) continue;
if (i==4) break;
}
18. Switch Case
Switch-case is a control statement to execute one block among many based on variable value. Each case
typically ends with a break. Example:
switch (x) {
case 1: printf("One"); break;
case 2: printf("Two"); break;
}
19. Actual Parameter and Formal Parameter
Actual parameters are passed by the caller; formal parameters are received by the function definition.
Example:
void display(int x) { printf("%d", x); } // x is formal
int main() {
display(5); // 5 is actual
}
20. Local and Global Variable
Local variables are declared within functions and accessible only there. Global variables are declared
outside and accessible throughout the program. Example:
int global = 10; // global
void func() {
4
int local = 5;
}
21. Program Counter
The Program Counter (PC) is a special register that holds the address of the next instruction to be
executed. It is crucial for instruction sequencing and flow control in CPU.
22. Difference Between Recursion and Iteration
Recursion uses function calls to repeat steps. Iteration uses loops like for or while. Recursion is elegant
but uses more memory (stack), whereas iteration is efficient in time and space. Example:
int fact(int n){ return n == 0 ? 1 : n * fact(n - 1); } // Recursion
for (i = 1; i <= n; i++) res *= i; // Iteration
23. Storage Class (auto, static, extern, register)
• auto : Default for local variables
• static : Retains value across function calls
• extern : Refers to global variables in other files
• register : Suggests faster access Example:
static int count;
extern int num;
register int i;
24. Function Call by Value and Call by Reference
Call by value passes a copy of the variable. Call by reference passes the address, allowing the function to
modify the original variable. Example:
void update(int *a) { *a = 20; }
int x = 10;
update(&x); // Call by reference
25. String and Function
A string in C is a null-terminated character array. Functions like strlen , strcpy , and strcmp
manipulate strings using pointers. Example:
char str[] = "Hello";
printf("%s", str);