C Exam Guide
Ad placement zone Responsive in-article banner (728×90 desktop / 320×100 mobile)
Chapter 1 — Data Types, Operators & I/O
Q1 Must Know State different data types supported by C language with memory size
Data TypeSizeRangeFormat
int2 or 4 bytes-32768 to 32767 (2B) / -2B to 2B (4B)%d
float4 bytes3.4E-38 to 3.4E+38%f
double8 bytes1.7E-308 to 1.7E+308%lf
char1 byte-128 to 127%c
long int4 bytes-2,147,483,648 to 2,147,483,647%ld
short int2 bytes-32768 to 32767%hd
void0 bytesNo value
⚡ Tricky Points
  • int size is NOT always 2 bytes — on modern 32/64-bit compilers (like GCC) it's 4 bytes. Say "2 or 4 bytes depending on compiler".
  • char stores ASCII valuechar c = 'A' stores 65 internally. You can do arithmetic on char.
  • float vs double — float has 6-7 significant digits precision; double has 15-16. Always use double for serious calculations.
  • Exam trick: they may ask "what is output of printf("%d", 'A')" — answer is 65.
Q2 Must Know List all relational operators with use/example
OperatorMeaningExampleResult
==Equal to5 == 51 (true)
!=Not equal to5 != 31 (true)
>Greater than7 > 31 (true)
<Less than3 < 71 (true)
>=Greater than or equal5 >= 51 (true)
<=Less than or equal3 <= 71 (true)

Relational operators return 1 (true) or 0 (false). Used in conditions of if, while, for.

⚡ Tricky Points
  • == vs = — Most common exam trap! if(a = 5) assigns 5 to a (always true). if(a == 5) checks equality.
  • Relational operators have lower precedence than arithmetica + b > c evaluates as (a+b) > c.
Q3 Must Know State use of %d and %f. Write example with printf.

%d — Format specifier for integer (int) values. Used in printf/scanf to read/write integer data.

%f — Format specifier for float values. Displays 6 decimal places by default.

example.c
#include <stdio.h>
void main() {
    int age = 20;
    float salary = 25000.50;
    printf("Age = %d\n", age);        // Output: Age = 20
    printf("Salary = %f\n", salary);   // Output: Salary = 25000.500000
    printf("Salary = %.2f\n", salary); // Output: Salary = 25000.50
}
⚡ Tricky Points
  • %.2f limits decimal places to 2. %5d means minimum 5 character width.
  • Using %d with a float will give garbage output — type must match specifier.
  • Other common specifiers: %c (char), %s (string), %lf (double), %o (octal), %x (hex).
Q4 Important Explain arithmetic operators with example (all 5)
OperatorNameExample (a=10, b=3)Result
+Additiona + b13
-Subtractiona - b7
*Multiplicationa * b30
/Divisiona / b3 (integer division!)
%Modulus (remainder)a % b1
⚡ Tricky Points
  • Integer division: 10/3 = 3 not 3.33. To get decimal: (float)10/3 = 3.33 (type casting).
  • Modulus only works on integers: 10.5 % 3 is a compile error.
  • Increment/Decrement: i++ (use then increment) vs ++i (increment then use).
  • Exam question: if a=5, what is b = a++? Answer: b=5, a=6. What is b = ++a? Answer: b=6, a=6.
Q5 Important Explain bitwise operators with example
OperatorNameExample (a=5=0101, b=3=0011)Result
&ANDa & b = 00011
|ORa | b = 01117
^XORa ^ b = 01106
~Complement~a-6
<<Left shifta << 1 = 101010
>>Right shifta >> 1 = 00102
⚡ Tricky Points
  • Left shift by n = multiply by 2^n: 5 << 1 = 10.
  • Right shift by n = divide by 2^n: 8 >> 2 = 2.
  • Don't confuse & (bitwise AND) with && (logical AND).
Q6 Important Explain conditional (ternary) operator with example

The conditional operator is the only ternary operator in C (takes 3 operands).

condition ? expression_if_true : expression_if_false
ternary.c
#include <stdio.h>
void main() {
    int a = 10, b = 20;
    int max = (a > b) ? a : b;
    printf("Max = %d", max);  // Output: Max = 20

    // Equivalent if-else:
    if(a > b) max = a;
    else max = b;
}
⚡ Tricky Points
  • Ternary operator can replace simple if-else but NOT complex blocks.
  • Exam may ask: compare if-else with ternary — ternary is shorter but less readable for complex logic.
Q7 Good to Know Define Token and Keyword. What are different types of tokens?

Token — The smallest individual unit in a C program that is meaningful to the compiler. A program is a collection of tokens.

Types of Tokens:

  • Keywords — Reserved words: int, float, if, while, return, void, char, etc.
  • Identifiers — Names given by programmer: variable names, function names
  • Constants — Fixed values: 10, 3.14, 'A', "Hello"
  • Operators — +, -, *, /, =, ==, etc.
  • Special symbols — { } ( ) [ ] ; , #
  • Strings — "Hello World"

Keyword — A word that has a fixed, predefined meaning in C. Cannot be used as variable names. C has 32 keywords.

⚡ Tricky Points
  • Keywords are always lowercase in C. Int is not a keyword — int is.
  • Identifiers cannot start with a digit: 2var is invalid, var2 is valid.
Q8 Good to Know Draw and explain flowchart symbols
Symbol ShapeNameUse
Oval / Rounded rectTerminalStart / End of flowchart
RectangleProcessArithmetic / Assignment operations
DiamondDecisionCondition check (if/while) — Yes/No branches
ParallelogramInput/Outputscanf / printf operations
ArrowFlow lineShows direction of flow
CircleConnectorConnects parts of large flowcharts
⚡ Tricky Points
  • Decision box (diamond) always has two exits: YES and NO.
  • Every flowchart must have exactly one START and one (or more) STOP.
Q9 Good to Know Distinguish between compiler and interpreter
Compiler
Interpreter
Translates entire program at once
Translates line by line
Generates object code (.exe)
No object code generated
Faster execution after compilation
Slower — translates every run
Errors shown after full scan
Stops at first error
C, C++, Java use compiler
Python, BASIC use interpreter
Q10 Program Program: Display number in decimal, octal, hexadecimal and binary
formats.c
#include <stdio.h>
void main() {
    int n, i, binary[32], count = 0;
    printf("Enter a number: ");
    scanf("%d", &n);

    printf("Decimal:     %d\n", n);
    printf("Octal:       %o\n", n);
    printf("Hexadecimal: %x\n", n);

    /* Binary conversion */
    int temp = n;
    while(temp > 0) {
        binary[count++] = temp % 2;
        temp = temp / 2;
    }
    printf("Binary:      ");
    for(i = count - 1; i >= 0; i--)
        printf("%d", binary[i]);
    printf("\n");
}
⚡ Tricky Points
  • Use %o for octal, %x for hex (lowercase), %X for uppercase hex.
  • Binary has no built-in format specifier — you must compute it manually by dividing by 2.
Q11 Program Program: Calculate simple interest SI = (P × N × R) / 100
si.c
#include <stdio.h>
void main() {
    float p, r, si;
    int n;
    printf("Enter Principal, Time (years), Rate: ");
    scanf("%f %d %f", &p, &n, &r);
    si = (p * n * r) / 100;
    printf("Simple Interest = %.2f", si);
}
Chapter 2 — Control Flow: if / switch / loops
Q1 Must Know Write syntax of if-else and explain with example
if(condition) {
    // statements if true
} else {
    // statements if false
}
ifelse.c
#include <stdio.h>
void main() {
    int n;
    printf("Enter number: ");
    scanf("%d", &n);
    if(n > 0)
        printf("Positive");
    else if(n < 0)
        printf("Negative");
    else
        printf("Zero");
}
⚡ Tricky Points
  • Dangling else problem: In nested if without braces, else belongs to the nearest if.
  • Without braces { }, only ONE statement is part of if/else. Use braces for multiple statements.
  • if(a = 5) is always true (assignment). Use if(a == 5) for comparison.
Q2 Must Know Explain nested if-else with example — find largest of three numbers

Nested if-else means an if-else inside another if-else block.

largest3.c
#include <stdio.h>
void main() {
    int a, b, c;
    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

    if(a > b) {
        if(a > c)
            printf("Largest = %d", a);
        else
            printf("Largest = %d", c);
    } else {
        if(b > c)
            printf("Largest = %d", b);
        else
            printf("Largest = %d", c);
    }
}
Q3 Must Know Give syntax of switch-case and explain with example
switch(expression) {
  case value1: statements; break;
  case value2: statements; break;
  default: statements;
}
switch.c
#include <stdio.h>
void main() {
    int choice;
    float a = 10, b = 3;
    printf("1.Add 2.Sub 3.Mul 4.Div: ");
    scanf("%d", &choice);

    switch(choice) {
        case 1: printf("Sum = %.2f", a+b); break;
        case 2: printf("Diff = %.2f", a-b); break;
        case 3: printf("Product = %.2f", a*b); break;
        case 4: printf("Quotient = %.2f", a/b); break;
        default: printf("Invalid choice");
    }
}
⚡ Tricky Points
  • Missing break causes fall-through: without break, execution continues into next case. This can be intentional but is usually a bug.
  • Switch works only with integer and char values — NOT float, string, or ranges.
  • default executes when no case matches. It is optional.
  • Exam trick: what is output if break is missing from case 1? All subsequent cases also execute!
Q4 Must Know Explain for loop with syntax, flowchart and example
for(initialization; condition; update) {
    // body
}

Execution order: 1) Initialize (once) → 2) Check condition → 3) Execute body → 4) Update → back to 2

forloop.c
#include <stdio.h>
void main() {
    int i;
    /* Print 1 to 10 */
    for(i = 1; i <= 10; i++) {
        printf("%d ", i);
    }
    /* Multiple statements in init/update */
    for(i = 10; i >= 1; i--) {   // reverse loop
        printf("%d ", i);
    }
}
⚡ Tricky Points
  • for(;;) is an infinite loop — all three parts are optional.
  • Variable declared inside for loop (for(int i=0;...)) is local to loop — only in C99+.
  • Off-by-one error: i < 10 runs 10 times (0-9), i <= 10 runs 11 times (0-10).
Q5 Must Know Compare while and do-while loop (4 points)
while loop
do-while loop
Entry-controlled loop
Exit-controlled loop
Condition checked BEFORE body executes
Condition checked AFTER body executes
Body may NOT execute if condition false initially
Body executes AT LEAST once
Syntax: while(cond) { ... }
Syntax: do { ... } while(cond);
Used when iteration count may be zero
Used for menus, input validation
loops_compare.c
/* while — may not execute */
int i = 10;
while(i < 5) {         // false, body skipped
    printf("%d", i);
}

/* do-while — always executes once */
do {
    printf("%d", i);   // prints 10 once
} while(i < 5);        // then checks — false, stops
⚡ Tricky Points
  • do-while has a semicolon after the while: while(cond); — forgetting this is a compile error.
  • If condition is true from the start, both loops behave identically.
Q6 Must Know State use of break and continue statements

break — Immediately exits the current loop or switch block. Execution continues after the loop.

continue — Skips the remaining statements of the current iteration and moves to the next iteration.

break_continue.c
#include <stdio.h>
void main() {
    int i;

    /* break example */
    for(i=1; i<=10; i++) {
        if(i == 5) break;    // stops at 5
        printf("%d ", i);      // prints: 1 2 3 4
    }

    /* continue example */
    for(i=1; i<=10; i++) {
        if(i == 5) continue;  // skips 5
        printf("%d ", i);      // prints: 1 2 3 4 6 7 8 9 10
    }
}
⚡ Tricky Points
  • break in nested loops only exits the innermost loop — not all loops.
  • continue in for loop still executes the update expression (i++) before the next iteration.
Q7 Program Write a C program to print Fibonacci series (loop + recursion)
fibonacci_loop.c
#include <stdio.h>
void main() {
    int n, a = 0, b = 1, c, i;
    printf("Enter number of terms: ");
    scanf("%d", &n);
    printf("%d %d ", a, b);
    for(i = 2; i < n; i++) {
        c = a + b;
        printf("%d ", c);
        a = b;
        b = c;
    }
}
// Output for n=8: 0 1 1 2 3 5 8 13
fibonacci_recursion.c
#include <stdio.h>
int fib(int n) {
    if(n <= 1) return n;
    return fib(n-1) + fib(n-2);
}
void main() {
    int i, n;
    printf("Enter terms: ");
    scanf("%d", &n);
    for(i = 0; i < n; i++)
        printf("%d ", fib(i));
}
⚡ Tricky Points
  • Fibonacci: 0, 1, 1, 2, 3, 5, 8, 13, 21... Each term = sum of previous two.
  • Recursive fib is simple to write but slow (exponential time) for large n.
Q8 Program Program to check if a number is prime
prime.c
#include <stdio.h>
void main() {
    int n, i, flag = 0;
    printf("Enter a number: ");
    scanf("%d", &n);
    if(n < 2) { printf("Not prime"); return; }
    for(i = 2; i <= n/2; i++) {
        if(n % i == 0) { flag = 1; break; }
    }
    if(flag == 0) printf("%d is Prime", n);
    else printf("%d is Not Prime", n);
}
⚡ Tricky Points
  • Check divisors only up to n/2 (or √n for efficiency). No divisor found → prime.
  • 1 is NOT a prime number. 2 is the only even prime.
Chapter 3 — Functions & Recursion
Q1 Must Know Define function. State difference between function definition and declaration.

Function — A self-contained block of code that performs a specific task, can accept input (parameters), and may return a value. Functions promote reusability and modularity.

Function Declaration (Prototype)
Function Definition
Tells compiler about function name, return type, parameters
Contains actual body/code of the function
Written before main() or in header
Can be written before or after main()
Ends with semicolon: int add(int,int);
Has curly braces with code block
functions.c
int add(int a, int b);  // Declaration (prototype)

void main() {
    printf("%d", add(3, 4));   // Function call
}

// Definition
int add(int a, int b) {
    return a + b;
}
Q2 Must Know Differentiate between call by value and call by reference (4 points)
Call by Value
Call by Reference
A copy of the value is passed
Address (memory location) is passed
Changes do NOT affect original variable
Changes DIRECTLY affect original variable
Uses normal variables as parameters
Uses pointers (*ptr) as parameters
Safer — no accidental modification
Used when we need to modify original
Example: add(a, b)
Example: swap(&a, &b)
call_by.c
/* Call by Value — original unchanged */
void addVal(int x) { x = x + 10; }

/* Call by Reference — original changes */
void addRef(int *x) { *x = *x + 10; }

void main() {
    int a = 5;
    addVal(a);          // a is still 5
    printf("%d\n", a);  // 5

    addRef(&a);         // a is now 15
    printf("%d\n", a);  // 15
}
⚡ Tricky Points
  • Arrays are ALWAYS passed by reference (address of first element is passed automatically).
  • Strings (char arrays) are also always passed by reference.
Q3 Must Know Explain recursive function with example (factorial)

Recursion — When a function calls itself repeatedly until a base condition (termination condition) is reached.

Every recursive function needs: 1) Base case (stopping condition) 2) Recursive call (moves toward base case)

factorial_recursion.c
#include <stdio.h>

int factorial(int n) {
    if(n == 0 || n == 1)  // base case
        return 1;
    return n * factorial(n - 1);  // recursive call
}
void main() {
    int n;
    printf("Enter n: ");
    scanf("%d", &n);
    printf("%d! = %d", n, factorial(n));
}
// factorial(4) = 4*factorial(3)
//              = 4*3*factorial(2)
//              = 4*3*2*factorial(1)
//              = 4*3*2*1 = 24

Advantages of recursion: Code is simpler and shorter; solves complex problems (trees, backtracking) elegantly; mirrors mathematical definitions.

⚡ Tricky Points
  • Without a base case → infinite recursion → stack overflow.
  • Recursion uses more memory (each call adds a stack frame) than iteration.
  • Exam may ask: trace factorial(4) step by step — be ready to write call stack.
Q4 Program Program: Add two numbers using function / multiply using function
add_multiply_functions.c
#include <stdio.h>

void add(int a, int b) {
    printf("Sum = %d\n", a + b);
}

void multiply(int a, int b) {
    printf("Product = %d\n", a * b);
}

void main() {
    int x, y;
    printf("Enter two numbers: ");
    scanf("%d %d", &x, &y);
    add(x, y);
    multiply(x, y);
}
Q5 Program Program: Calculate gross salary using user-defined function calculate()
salary.c
#include <stdio.h>

void calculate(float basic) {
    float da, hra, gross;
    da    = 0.10 * basic;   // 10% DA
    hra   = 0.083 * basic;  // 8.3% HRA
    gross = basic + da + hra;
    printf("Basic = %.2f\n", basic);
    printf("DA    = %.2f\n", da);
    printf("HRA   = %.2f\n", hra);
    printf("Gross = %.2f\n", gross);
}

void main() {
    int empno;
    float basic;
    printf("Enter Employee No and Basic Salary: ");
    scanf("%d %f", &empno, &basic);
    printf("Employee No: %d\n", empno);
    calculate(basic);
}
Chapter 4 — Arrays (1D and 2D)
Q1 Must Know Define array. State two advantages. Explain how elements are accessed.

Array — A collection of elements of the same data type stored in contiguous memory locations, accessed using a single variable name and an index.

Advantages:

  • Multiple values stored using a single variable name — reduces code complexity.
  • Elements accessed randomly using index in O(1) time — very efficient.
  • Easy to sort and search using loops.
// Declaration
datatype arrayname[size];

// Accessing elements
arrayname[index] // index starts from 0
array_access.c
#include <stdio.h>
void main() {
    int a[5] = {10, 20, 30, 40, 50};
    int i;
    // a[0]=10, a[1]=20, ..., a[4]=50
    for(i = 0; i < 5; i++)
        printf("a[%d] = %d\n", i, a[i]);
}
⚡ Tricky Points
  • Array index starts at 0. An array of size n has indices 0 to n-1. Accessing a[n] is out of bounds (undefined behaviour).
  • int a[5] = {1, 2}; — remaining elements are automatically initialized to 0.
  • int a[] = {1, 2, 3}; — compiler sets size to 3 automatically.
  • Exam trap: array name without index gives the address of first element.
Q2 Must Know Describe declaration and initialization of 2D array with example

A 2D array stores elements in a table format (rows and columns). Also called a matrix.

datatype arrayname[rows][cols];
// Example:
int matrix[3][3];
2d_array.c
#include <stdio.h>
void main() {
    /* Initialization at declaration */
    int a[3][3] = {
        {1, 2, 3},
        {4, 5, 6},
        {7, 8, 9}
    };

    int i, j;
    for(i = 0; i < 3; i++) {
        for(j = 0; j < 3; j++)
            printf("%d ", a[i][j]);
        printf("\n");
    }
    // Access element at row 1, col 2: a[1][2] = 6
}
⚡ Tricky Points
  • Memory layout: 2D arrays are stored in row-major order — all of row 0 first, then row 1, etc.
  • a[i][j] is located at address: base + (i * cols + j) * sizeof(datatype).
  • When declaring parameter in a function, first dimension can be omitted but NOT second: void f(int a[][3]).
Q3 Must Know Program: Add two 3×3 matrices
matrix_add.c
#include <stdio.h>
void main() {
    int a[3][3], b[3][3], c[3][3], i, j;

    printf("Enter Matrix A (3x3):\n");
    for(i=0; i<3; i++)
        for(j=0; j<3; j++)
            scanf("%d", &a[i][j]);

    printf("Enter Matrix B (3x3):\n");
    for(i=0; i<3; i++)
        for(j=0; j<3; j++)
            scanf("%d", &b[i][j]);

    /* Addition */
    for(i=0; i<3; i++)
        for(j=0; j<3; j++)
            c[i][j] = a[i][j] + b[i][j];

    printf("Sum Matrix:\n");
    for(i=0; i<3; i++) {
        for(j=0; j<3; j++)
            printf("%d\t", c[i][j]);
        printf("\n");
    }
}
Q4 Program Program: Multiply two 3×3 matrices
matrix_multiply.c
#include <stdio.h>
void main() {
    int a[3][3], b[3][3], c[3][3] = {0};
    int i, j, k;

    /* Input a and b matrices here (same as above) */

    /* Multiplication: c[i][j] = sum of a[i][k]*b[k][j] */
    for(i=0; i<3; i++)
        for(j=0; j<3; j++)
            for(k=0; k<3; k++)
                c[i][j] += a[i][k] * b[k][j];

    printf("Result:\n");
    for(i=0; i<3; i++) {
        for(j=0; j<3; j++)
            printf("%d\t", c[i][j]);
        printf("\n");
    }
}
⚡ Tricky Points
  • Matrix multiplication needs 3 nested loops. Initialize c to 0 before using += accumulator.
  • Matrix multiplication is only possible if cols of A = rows of B.
Q5 Program Program: Find largest number from an array of 10 numbers
largest_array.c
#include <stdio.h>
void main() {
    int a[10], i, max;
    printf("Enter 10 numbers:\n");
    for(i=0; i<10; i++)
        scanf("%d", &a[i]);

    max = a[0];   // assume first is largest
    for(i=1; i<10; i++) {
        if(a[i] > max)
            max = a[i];
    }
    printf("Largest = %d", max);
}
Q6 Program Program: Sort array in ascending order (Bubble Sort)
bubble_sort.c
#include <stdio.h>
void main() {
    int a[10], i, j, temp, n = 10;
    printf("Enter 10 numbers:\n");
    for(i=0; i<n; i++) scanf("%d", &a[i]);

    /* Bubble sort */
    for(i=0; i<n-1; i++) {
        for(j=0; j<n-i-1; j++) {
            if(a[j] > a[j+1]) {
                temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
        }
    }
    printf("Sorted: ");
    for(i=0; i<n; i++) printf("%d ", a[i]);
}
⚡ Tricky Points
  • Bubble sort: inner loop runs n-i-1 times (already sorted elements at end are skipped).
  • Swap always uses a temp variable: temp=a[j]; a[j]=a[j+1]; a[j+1]=temp;
Chapter 5 — Strings & String Functions
Q1 Must Know State ways of declaration and initialization of string variables

A string in C is an array of characters terminated by a null character '\0'.

strings_init.c
/* Method 1: char array with initialization */
char name[20] = "Hello";

/* Method 2: char array with char list */
char name[] = {'H','e','l','l','o','\0'};

/* Method 3: pointer to string literal */
char *name = "Hello";

/* Input using scanf (no spaces) */
scanf("%s", name);

/* Input using gets (includes spaces) */
gets(name);

/* Output */
printf("%s", name);
puts(name);  // same as printf with newline
⚡ Tricky Points
  • Always allocate 1 extra byte for '\0'. "Hello" needs char[6], not char[5].
  • scanf("%s") stops at space. Use gets() to read full line with spaces.
  • Array size must be specified when declaring without initialization.
Q2 Must Know Explain strlen() and strcpy() with example

strlen(s) — Returns the length of string s (number of characters before '\0').

strcpy(dest, src)Copies src string into dest string, including '\0'.

strlen_strcpy.c
#include <stdio.h>
#include <string.h>
void main() {
    char s1[20] = "Hello";
    char s2[20];

    printf("Length = %lu\n", strlen(s1)); // 5
    strcpy(s2, s1);
    printf("Copied: %s\n", s2);            // Hello
}
⚡ Tricky Points
  • strlen does NOT count '\0'. "Hello" → length 5.
  • sizeof("Hello") returns 6 (includes '\0') — different from strlen!
  • strcpy order: destination first, then source. Like assignment: dest = src.
  • Need #include <string.h> for all string functions.
Q3 Must Know Explain strcmp() and strcat() with example

strcmp(s1, s2) — Compares two strings. Returns 0 if equal, positive if s1 > s2, negative if s1 < s2.

strcat(s1, s2) — Appends (concatenates) s2 to the end of s1. s1 must be large enough.

strcmp_strcat.c
#include <stdio.h>
#include <string.h>
void main() {
    char s1[50] = "Hello";
    char s2[] = " World";

    /* strcmp */
    if(strcmp(s1, s2) == 0)
        printf("Strings are equal\n");
    else
        printf("Strings are different\n");

    /* strcat */
    strcat(s1, s2);
    printf("Concatenated: %s\n", s1); // Hello World
}
⚡ Tricky Points
  • strcmp returns 0 for equal — NOT 1. Beginners confuse this with true/false.
  • strcat modifies s1 — s1 must have enough space for s1 + s2.
  • strcmp is case-sensitive: "hello" ≠ "Hello".
Q4 Program Program: Accept two strings, display lengths, concatenate and display
strings_program.c
#include <stdio.h>
#include <string.h>
void main() {
    char s1[100], s2[50];
    printf("Enter string 1: ");
    scanf("%s", s1);
    printf("Enter string 2: ");
    scanf("%s", s2);

    printf("Length of s1 = %lu\n", strlen(s1));
    printf("Length of s2 = %lu\n", strlen(s2));

    strcat(s1, s2);
    printf("Concatenated string: %s\n", s1);
}
Q5 Program Program: Check if string is palindrome
palindrome.c
#include <stdio.h>
#include <string.h>
void main() {
    char s[50], rev[50];
    printf("Enter a string: ");
    scanf("%s", s);

    strcpy(rev, s);
    strrev(rev);   // reverses string

    if(strcmp(s, rev) == 0)
        printf("\"%s\" is a Palindrome", s);
    else
        printf("\"%s\" is NOT a Palindrome", s);
}
// "madam" reversed = "madam" → Palindrome
// "hello" reversed = "olleh" → Not palindrome
⚡ Tricky Points
  • strrev() is available in some compilers (Turbo C) but not GCC. If not available, write manual reverse using a loop.
  • Palindrome examples: "madam", "racecar", "level", "12321".
Q6 Program Program: Copy string without using strcpy
manual_copy.c
#include <stdio.h>
void main() {
    char src[50], dest[50];
    int i = 0;
    printf("Enter string: ");
    scanf("%s", src);

    while(src[i] != '\0') {
        dest[i] = src[i];
        i++;
    }
    dest[i] = '\0';  // important: add null terminator
    printf("Copied: %s", dest);
}
⚡ Tricky Points
  • Always add '\0' at end of manually copied string — without it, printf will print garbage.
Chapter 6 — Pointers
Q1 Must Know Define pointer. State use of * and & operators. Explain declaration and initialization.

Pointer — A variable that stores the memory address of another variable instead of storing a data value directly.

& (Address-of operator) — Returns the memory address of a variable. Used to initialize pointers.

* (Dereference/Indirection operator) — Accesses/modifies the value at the address stored in a pointer. Also used to declare a pointer variable.

datatype *pointer_name; // Declaration
pointer_name = &variable; // Initialization
pointer_basics.c
#include <stdio.h>
void main() {
    int a = 50;
    int *p;         // p is a pointer to int
    p = &a;         // p stores address of a

    printf("Value of a  = %d\n", a);    // 50
    printf("Address of a= %p\n", &a);   // e.g. 0x7ffd
    printf("p holds     = %p\n", p);    // same address
    printf("Value via p = %d\n", *p);   // 50 (dereferencing)

    *p = 100;    // changes a through pointer
    printf("New a = %d\n", a);    // 100
}
⚡ Tricky Points — Pointer meaning decoding
  • int *p — p is a pointer to an integer
  • int **p — p is a pointer to a pointer to int (double pointer)
  • *p — value at address stored in p (dereference)
  • &a — address of variable a
  • Exam question: int var=50; int *p1,*p2; p1=&var; p2=p1;
    → var=50, p1=address of var, p2=same address as p1, *p1=50, *p2=50
  • Null pointer: int *p = NULL; — pointer not pointing to anything. Dereferencing NULL crashes program.
Q2 Must Know Explain pointer arithmetic with all operations

Arithmetic operations that can be performed on pointers:

OperationMeaningExample (int *p, 4-byte int)
p++ or p+1Move to next elementAddress increases by 4
p-- or p-1Move to previous elementAddress decreases by 4
p + nMove n elements forwardAddress + n*sizeof(int)
p2 - p1Number of elements betweenReturns integer count
pointer_arithmetic.c
#include <stdio.h>
void main() {
    int a[5] = {10,20,30,40,50};
    int *p = a;  // p points to a[0]

    printf("%d\n", *p);    // 10 (a[0])
    p++;
    printf("%d\n", *p);    // 20 (a[1])
    p += 2;
    printf("%d\n", *p);    // 40 (a[3])
    p--;
    printf("%d\n", *p);    // 30 (a[2])
}
⚡ Tricky Points
  • p++ increments by sizeof(datatype), not by 1 byte. For int: +4 bytes.
  • You cannot multiply or divide pointers: p*2 is invalid.
  • You cannot add two pointers: p1+p2 is invalid. But p1-p2 is valid (gives distance between them).
Q3 Must Know Explain advantages of pointers (4 points)
  • Dynamic memory allocation — Using malloc(), calloc() to allocate memory at runtime.
  • Pass by reference — Functions can modify original variables through pointers.
  • Efficient array access — Array traversal using pointer arithmetic is faster than index-based access.
  • Data structures — Linked lists, trees, graphs require pointers to link nodes.
  • Multiple return values — Function can return multiple values via pointer parameters.
  • Reduced code size — Avoids copying large data structures; pass address instead.
Q4 Program Program: Swap two numbers using pointers
swap_pointers.c
#include <stdio.h>

void swap(int *a, int *b) {
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}

void main() {
    int x, y;
    printf("Enter two numbers: ");
    scanf("%d %d", &x, &y);
    printf("Before: x=%d y=%d\n", x, y);
    swap(&x, &y);
    printf("After:  x=%d y=%d\n", x, y);
}
⚡ Tricky Points
  • Call with &x, &y — addresses. Function receives *a, *b — pointers.
  • Without pointers (call by value), swap would NOT work — original x and y unchanged.
Q5 Program Program: Access array elements using pointer
array_pointer.c
#include <stdio.h>
void main() {
    int a[5] = {10,20,30,40,50};
    int *p, i;
    p = a;   // or p = &a[0];

    printf("Array elements using pointer:\n");
    for(i = 0; i < 5; i++)
        printf("a[%d] = %d\n", i, *(p+i));

    /* These are all equivalent: */
    // a[i] == *(a+i) == *(p+i) == p[i]
}
⚡ Tricky Points
  • Array name is a constant pointer — you cannot do a++ (illegal), but p++ is fine.
  • a[i] and *(a+i) are exactly equivalent internally.
Q6 Program Program: Find product of two numbers using pointer
product_pointer.c
#include <stdio.h>
void main() {
    int a, b, product;
    int *p1, *p2;
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);
    p1 = &a;
    p2 = &b;
    product = (*p1) * (*p2);
    printf("Product = %d", product);
}
Chapter 7 — Structures
Q1 Must Know Define structure. Explain declaration with example. State two features.

Structure — A user-defined data type that groups together variables of different data types under a single name. Each variable inside is called a member.

Features:

  • Can hold different data types (int, float, char) in one unit — unlike arrays.
  • Memory is allocated for all members together.
  • Members accessed using dot (.) operator.
struct tag_name {
  datatype member1;
  datatype member2;
};
struct tag_name variable_name;
structure_basic.c
#include <stdio.h>

struct student {
    int   roll_no;
    char  name[50];
    float marks;
};

void main() {
    struct student s;

    printf("Enter roll no, name, marks: ");
    scanf("%d %s %f", &s.roll_no, s.name, &s.marks);

    printf("Roll No: %d\n", s.roll_no);
    printf("Name:    %s\n", s.name);
    printf("Marks:   %.2f\n", s.marks);
}
⚡ Tricky Points
  • Structure definition ends with a semicolon after closing brace: };
  • Structure definition does NOT allocate memory — only declaring a variable does.
  • For string member, use scanf("%s", s.name) — no & because name is already an address.
  • Use dot (.) operator with variable. Use arrow (->) operator with pointer to struct.
Q2 Must Know Explain array of structures with example (book with 10 books)

An array of structures allows storing multiple records of the same structure type.

array_of_struct.c
#include <stdio.h>

struct book {
    int   book_no;
    char  book_title[50];
    float book_price;
};

void main() {
    struct book b[10];
    int i;

    for(i = 0; i < 10; i++) {
        printf("Enter Book %d (no title price): ", i+1);
        scanf("%d %s %f",
              &b[i].book_no,
              b[i].book_title,
              &b[i].book_price);
    }

    printf("\n--- Book List ---\n");
    for(i = 0; i < 10; i++) {
        printf("%d  %-20s  %.2f\n",
               b[i].book_no,
               b[i].book_title,
               b[i].book_price);
    }
}
Q3 Must Know Declare structure DATE with day, month, year and assign initial values
date_struct.c
#include <stdio.h>

struct DATE {
    int day;
    int month;
    int year;
};

void main() {
    /* Initialization at declaration */
    struct DATE d = {15, 8, 2024};

    printf("Date: %d/%d/%d", d.day, d.month, d.year);
    // Output: Date: 15/8/2024
}
Q4 Must Know Declare structure circle with radius, area, perimeter. Accept radius, find area and perimeter.
circle_struct.c
#include <stdio.h>
#define PI 3.14159

struct circle {
    float radius;
    float area;
    float perimeter;
};

void main() {
    struct circle c;

    printf("Enter radius: ");
    scanf("%f", &c.radius);

    c.area      = PI * c.radius * c.radius;
    c.perimeter = 2 * PI * c.radius;

    printf("Area      = %.2f\n", c.area);
    printf("Perimeter = %.2f\n", c.perimeter);
}
Q5 Must Know Explain arrow (->) operator with example (pointer to structure)

The arrow operator (->) is used to access structure members through a pointer to a structure.

ptr->member is equivalent to (*ptr).member

arrow_operator.c
#include <stdio.h>

struct student {
    int  roll;
    char name[30];
};

void main() {
    struct student s = {10, "Riya"};
    struct student *p = &s;  // pointer to struct

    /* Two equivalent ways to access: */
    printf("%d %s\n", (*p).roll, (*p).name);  // old way
    printf("%d %s\n", p->roll, p->name);      // arrow way (preferred)
}
⚡ Tricky Points
  • Dot (.) is used with structure variable. Arrow (->) is used with pointer to structure.
  • Exam question: "When do we use -> operator?" — Answer: when accessing members via a pointer.
Q6 Program Program: Structure student with roll_no, name, marks in 3 subjects, display % marks
student_percentage.c
#include <stdio.h>

struct student {
    int   roll_no;
    char  name[50];
    float m1, m2, m3;
};

void main() {
    struct student s;
    float total, percent;

    printf("Enter Roll No: ");
    scanf("%d", &s.roll_no);
    printf("Enter Name: ");
    scanf("%s", s.name);
    printf("Enter marks in 3 subjects: ");
    scanf("%f %f %f", &s.m1, &s.m2, &s.m3);

    total   = s.m1 + s.m2 + s.m3;
    percent = (total / 300.0) * 100;

    printf("Roll No: %d\n", s.roll_no);
    printf("Name:    %s\n", s.name);
    printf("Total:   %.2f\n", total);
    printf("Percent: %.2f%%\n", percent);
}
Q7 Program Write structure 'account' with account_no, account_type, account_name, account_balance
account_struct.c
#include <stdio.h>

struct account {
    int   account_no;
    char  account_type[20];   // Savings/Current
    char  account_name[50];
    float account_balance;
};

void main() {
    struct account a;
    printf("Enter Account No: ");
    scanf("%d", &a.account_no);
    printf("Enter Account Type: ");
    scanf("%s", a.account_type);
    printf("Enter Account Name: ");
    scanf("%s", a.account_name);
    printf("Enter Balance: ");
    scanf("%f", &a.account_balance);

    printf("\nAccount No:   %d\n", a.account_no);
    printf("Account Type: %s\n", a.account_type);
    printf("Account Name: %s\n", a.account_name);
    printf("Balance:      %.2f\n", a.account_balance);
}
Chapter 8 — All Important Programs at a Glance
P1 6/6 Papers Swap two numbers using pointers
swap.c
#include <stdio.h>
void swap(int *a, int *b) {
    int t = *a; *a = *b; *b = t;
}
void main() {
    int x, y;
    scanf("%d %d", &x, &y);
    swap(&x, &y);
    printf("x=%d y=%d", x, y);
}
P2 5/6 Papers Add two 3×3 matrices
matrix_add.c
#include <stdio.h>
void main() {
    int a[3][3],b[3][3],c[3][3],i,j;
    printf("Enter Matrix A:\n");
    for(i=0;i<3;i++) for(j=0;j<3;j++) scanf("%d",&a[i][j]);
    printf("Enter Matrix B:\n");
    for(i=0;i<3;i++) for(j=0;j<3;j++) scanf("%d",&b[i][j]);
    for(i=0;i<3;i++) for(j=0;j<3;j++) c[i][j]=a[i][j]+b[i][j];
    printf("Sum:\n");
    for(i=0;i<3;i++){for(j=0;j<3;j++)printf("%d ",c[i][j]);printf("\n");}
}
P3 6/6 Papers Add two numbers using function
add_func.c
#include <stdio.h>
int add(int a, int b) { return a+b; }
void main() {
    int x,y;
    scanf("%d %d",&x,&y);
    printf("Sum=%d",add(x,y));
}
P4 5/6 Papers Factorial using recursion
factorial.c
#include <stdio.h>
int fact(int n) {
    if(n<=1) return 1;
    return n*fact(n-1);
}
void main() {
    int n; scanf("%d",&n);
    printf("%d!=%d",n,fact(n));
}
P5 4/6 Papers Fibonacci series (recursion)
fib.c
#include <stdio.h>
int fib(int n){if(n<=1)return n;return fib(n-1)+fib(n-2);}
void main(){
    int i,n; scanf("%d",&n);
    for(i=0;i<n;i++) printf("%d ",fib(i));
}
P6 6/6 Papers Positive / Negative check
posneg.c
#include <stdio.h>
void main(){
    int n; scanf("%d",&n);
    if(n>0) printf("Positive");
    else if(n<0) printf("Negative");
    else printf("Zero");
}
P7 5/6 Papers Structure: student with roll no, name, marks
student.c
#include <stdio.h>
struct student { int roll; char name[50]; float marks; };
void main(){
    struct student s;
    scanf("%d %s %f",&s.roll,s.name,&s.marks);
    printf("Roll:%d Name:%s Marks:%.2f",s.roll,s.name,s.marks);
}
P8 5/6 Papers Largest of three numbers (nested if-else)
largest3.c
#include <stdio.h>
void main(){
    int a,b,c; scanf("%d%d%d",&a,&b,&c);
    if(a>b){ if(a>c)printf("Largest=%d",a); elseprintf("Largest=%d",c); }
    else{ if(b>c)printf("Largest=%d",b); elseprintf("Largest=%d",c); }
}
P9 5/6 Papers String: accept two strings, find lengths, concatenate
strings2.c
#include <stdio.h>
#include <string.h>
void main(){
    char s1[100],s2[50];
    scanf("%s%s",s1,s2);
    printf("Len1=%lu Len2=%lu\n",strlen(s1),strlen(s2));
    strcat(s1,s2);
    printf("Concat:%s",s1);
}
P10 4/6 Papers Print table of a number
table.c
#include <stdio.h>
void main(){
    int n,i; scanf("%d",&n);
    for(i=1;i<=10;i++)
        printf("%d x %d = %d\n",n,i,n*i);
}
P11 4/6 Papers Circle structure (radius, area, perimeter)
circle.c
#include <stdio.h>
#define PI 3.14159
struct circle { float r,a,p; };
void main(){
    struct circle c;
    scanf("%f",&c.r);
    c.a=PI*c.r*c.r; c.p=2*PI*c.r;
    printf("Area=%.2f Perimeter=%.2f",c.a,c.p);
}
P12 3/6 Papers Sum of natural numbers / sum of digits
sum_natural.c
#include <stdio.h>
void main(){
    int n,i,sum=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++) sum+=i;
    printf("Sum=%d",sum);
}

/* Sum of digits of a number */
void sumDigits(){
    int n,sum=0;
    scanf("%d",&n);
    while(n!=0){ sum+=n%10; n/=10; }
    printf("Sum of digits=%d",sum);
}
P13 Bonus Check vowel or consonant
vowel.c
#include <stdio.h>
void main(){
    char c; scanf("%c",&c);
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||
       c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
        printf("Vowel");
    else
        printf("Consonant");
}
P14 Bonus Gross salary: Basic + 5% DA + 15% TA
salary2.c
#include <stdio.h>
void main(){
    float basic,da,ta,gross;
    printf("Enter basic salary: ");
    scanf("%f",&basic);
    da=0.05*basic;   // 5% DA
    ta=0.15*basic;   // 15% TA
    gross=basic+da+ta;
    printf("DA=%.2f TA=%.2f Gross=%.2f",da,ta,gross);
}
P15 Bonus Quadratic equation roots: ax²+bx+c=0
quadratic.c
#include <stdio.h>
#include <math.h>
void main(){
    float a,b,c,disc,r1,r2;
    scanf("%f%f%f",&a,&b,&c);
    disc = b*b - 4*a*c;
    if(disc > 0){
        r1=(-b+sqrt(disc))/(2*a);
        r2=(-b-sqrt(disc))/(2*a);
        printf("Roots: %.2f and %.2f",r1,r2);
    } else if(disc==0){
        r1=-b/(2*a);
        printf("Equal roots: %.2f",r1);
    } else
        printf("Imaginary roots");
}
⚡ Tricky Points
  • Discriminant = b²-4ac: >0 → 2 real roots, =0 → equal roots, <0 → imaginary.
  • Need #include <math.h> for sqrt(). Compile with -lm flag on GCC.