⬅ Previous Next ➡

Interview & Projects

Interview & Projects (C Programming)
  • This section covers common C interview questions, problem-solving practice, and mini projects to build real-world skills.
  • Focus areas: pointers, arrays/strings, memory, structures, file handling, and data structures basics.

1) Common C Interview Questions (Quick List)

  • What is the difference between declaration and definition?
  • What is the difference between stack and heap memory?
  • What are dangling, wild, and NULL pointers?
  • Explain call by value vs call by reference.
  • Difference between struct and union.
  • What is static keyword (local and global use)?
  • Difference between malloc and calloc.
  • What is realloc and when to use it?
  • Why do we use header files and include guards?
  • Explain pointer arithmetic and array-pointer relation.
  • How strings are stored in C? What is \0?
  • What is a segmentation fault and common reasons?

2) Problem-Solving Practice (Code Programs)

2.1) Reverse a Number
#include <stdio.h>

int main() {
    int n = 12345, rev = 0;

    while (n != 0) {
        rev = rev * 10 + (n % 10);
        n = n / 10;
    }

    printf("Reverse = %d\n", rev);
    return 0;
}
2.2) Check Palindrome String
#include <stdio.h>
#include <string.h>

int main() {
    char s[50] = "level";
    int i, j;
    int ok = 1;

    i = 0;
    j = (int)strlen(s) - 1;

    while (i < j) {
        if (s[i] != s[j]) {
            ok = 0;
            break;
        }
        i++;
        j--;
    }

    printf("Palindrome? %s\n", ok ? "Yes" : "No");
    return 0;
}
2.3) Find Maximum in Array
#include <stdio.h>

int main() {
    int a[6] = {12, 9, 30, 5, 22, 18};
    int max = a[0];

    for (int i = 1; i < 6; i++) {
        if (a[i] > max) max = a[i];
    }

    printf("Max = %d\n", max);
    return 0;
}
2.4) Swap Two Numbers (Pointers)
#include <stdio.h>

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

int main() {
    int x = 10, y = 20;

    printf("Before: x=%d y=%d\n", x, y);
    swap(&x, &y);
    printf("After : x=%d y=%d\n", x, y);

    return 0;
}

3) Mini Projects (Real-world Practice)

3.1) Student Record Management (File Based)
  • Features:
    • Add student (id, name, marks)
    • View all records
    • Search by id
  • Concepts: struct + file handling (fwrite/fread).
#include <stdio.h>
#include <string.h>

struct Student {
    int id;
    char name[30];
    float marks;
};

int main() {
    struct Student s = {1, "Sourav", 88.5f};

    FILE *fp = fopen("students.dat", "ab");
    if (fp == NULL) return 0;

    fwrite(&s, sizeof(struct Student), 1, fp);
    fclose(fp);

    printf("Record saved.\n");
    return 0;
}
3.2) Mini Banking System (Console)
  • Features:
    • Create account
    • Deposit/withdraw
    • Balance check
  • Concepts: functions + validation + loops.
#include <stdio.h>

int main() {
    int choice;
    float bal = 0, amt;

    while (1) {
        printf("\n1.Deposit 2.Withdraw 3.Balance 4.Exit\n");
        scanf("%d", &choice);

        if (choice == 1) {
            printf("Amount: ");
            scanf("%f", &amt);
            if (amt > 0) bal += amt;

        } else if (choice == 2) {
            printf("Amount: ");
            scanf("%f", &amt);
            if (amt > 0 && amt <= bal) bal -= amt;

        } else if (choice == 3) {
            printf("Balance = %.2f\n", bal);

        } else if (choice == 4) {
            break;

        } else {
            printf("Invalid choice!\n");
        }
    }

    return 0;
}
3.3) To-Do List (File Based Simple Project)
  • Features:
    • Add task
    • View tasks
    • Mark done (optional)
  • Concepts: file I/O + strings.
#include <stdio.h>

int main() {
    int ch;
    char task[100];

    printf("1.Add Task 2.View Tasks\n");
    scanf("%d", &ch);
    getchar(); // consume newline

    if (ch == 1) {
        FILE *fp = fopen("todo.txt", "a");
        if (fp == NULL) return 0;

        printf("Enter task: ");
        fgets(task, sizeof(task), stdin);

        fputs(task, fp);
        fclose(fp);
        printf("Task saved.\n");

    } else if (ch == 2) {
        FILE *fp = fopen("todo.txt", "r");
        if (fp == NULL) {
            printf("No tasks found.\n");
            return 0;
        }

        while (fgets(task, sizeof(task), fp) != NULL) {
            printf("%s", task);
        }
        fclose(fp);
    }

    return 0;
}

4) Final Project Idea (Recommended)

  • Library Management System (C) (Console + File Handling)
  • Modules:
    • Add book, view books
    • Issue/return book
    • Search by book id/name
    • Store records in file
  • Extra features:
    • Admin login (simple)
    • Fine calculation
    • Report generation

5) Quick Notes

  • Practice writing clean logic with loops and functions.
  • Strong focus on pointers and memory management for interviews.
  • Mini projects help you show real skills in resumes and exams.
  • Always handle file errors and validate user input.
⬅ Previous Next ➡