100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C

Common C Interview Questions

Top C programming interview questions and answers covering pointers, memory allocation, storage classes, structures, and const/volatile.

Algorithms & Interview PrepIntermediate14 min readJul 7, 2026
Analogies

1. Introduction

C interviews frequently test a candidate's understanding of low-level concepts such as memory management, pointers, and storage classes, since these topics reveal how well a candidate understands what is happening 'under the hood' in a program. This guide covers the most commonly asked C interview questions, each explained clearly with the reasoning an interviewer expects to hear. Mastering these concepts will help you confidently answer both theoretical and practical C interview rounds.

🏏

Cricket analogy: Just as a fast bowler's true skill is judged by seam position and wrist snap invisible to fans, C interviews probe pointers and memory management to see what's really happening under the hood of a program.

2. Syntax

c
/* Quick reference to syntax used throughout this Q&A set */
int *p;                 /* pointer declaration           */
int arr[5];              /* array declaration             */
malloc(n * sizeof(int)); /* uninitialized heap allocation */
calloc(n, sizeof(int));  /* zero-initialized heap allocation */
static int x;             /* static storage class          */
const int y = 10;         /* read-only variable            */
volatile int flag;        /* value may change unexpectedly */
#ifndef HEADER_H
#define HEADER_H          /* header guard pattern          */
#endif

3. Explanation

Q: What is the difference between a pointer and an array in C? A: An array name decays into a pointer to its first element in most expressions, but they are not identical. sizeof(arr) gives the total size of the array in bytes, while sizeof(ptr) gives the size of a pointer (typically 8 bytes on 64-bit systems). Arrays allocate fixed, contiguous memory at declaration and cannot be reassigned to point elsewhere, whereas pointers are variables that can be reassigned to point to different memory locations at any time.

🏏

Cricket analogy: An array is like a fixed 11-player squad announced before the toss that can't be swapped mid-innings, while a pointer is like a substitute fielder who can be reassigned to cover any position.

Q: What is the difference between malloc() and calloc()? A: Both allocate memory dynamically on the heap, but malloc(size) allocates a single block of 'size' bytes with indeterminate (garbage) initial values, while calloc(n, size) allocates memory for 'n' elements of 'size' bytes each and initializes all bytes to zero. calloc() also internally guards against multiplication overflow, whereas malloc() requires the caller to compute the total size correctly.

🏏

Cricket analogy: malloc() is like handing a groundskeeper a patch of pitch without prepping it, leaving unpredictable bounce, while calloc() is like rolling and leveling that same patch first so every ball behaves predictably.

Q: C only supports call by value, so how do we simulate call by reference? A: C passes arguments by value, meaning a function receives a copy of the argument. To let a function modify the caller's original variable, you pass the address of that variable (a pointer) instead. The function then dereferences the pointer to read or modify the original value, effectively simulating pass-by-reference behavior, as seen in functions like scanf("%d", &x) or a swap(int *a, int *b) function.

🏏

Cricket analogy: Since C only passes a copy of a value, like handing a scorer a photocopy of the scoresheet they can't officially update, you instead give them the actual scorebook's location so edits like a swapped batting order stick.

Q: What is the difference between a static variable and a global variable? A: A global variable is declared outside any function and has file scope with external linkage by default, meaning it can be accessed from other source files using extern. A static variable declared at file scope has internal linkage, restricting its visibility to the file it's declared in. A static variable declared inside a function retains its value between function calls (unlike a normal local variable) but is only visible within that function.

🏏

Cricket analogy: A global variable is like a national team roster visible and editable by any state association via 'extern', while a function-local static is like a bowler's personal wicket tally that persists match to match, hidden from others.

Q: What is structure padding, and why does it happen? A: Structure padding is the insertion of unused bytes between structure members (or after the last member) by the compiler to satisfy each member's memory alignment requirements, which allows the CPU to access data more efficiently. For example, a struct with a char followed by an int may have 3 padding bytes inserted after the char so the int starts at a 4-byte aligned address, making sizeof(struct) larger than the sum of its members' individual sizes.

🏏

Cricket analogy: Structure padding is like a team bus leaving gaps between certain players' seats so heavier equipment bags align properly in the aisle, making the bus's total length bigger than just the sum of passengers.

Q: What does the const keyword guarantee, and where can it be placed with pointers? A: const marks a variable as read-only after initialization; any attempt to modify it causes a compile-time error. With pointers, placement matters: 'const int *p' means the data pointed to cannot be modified through p (but p itself can point elsewhere), 'int *const p' means p itself cannot be reassigned (but the data it points to can be modified), and 'const int *const p' means neither the pointer nor the pointed-to data can change.

🏏

Cricket analogy: 'const int *p' is like a commentator who can watch the scoreboard but not change it, while switching booths; 'int *const p' is a commentator locked to one booth but free to update that scoreboard; 'const int *const p' is locked to one booth and can't touch the scoreboard at all.

Q: What does the volatile keyword do, and when is it needed? A: volatile tells the compiler that a variable's value may change at any time outside the normal flow of the program (for example, by hardware, an interrupt service routine, or another thread), so the compiler must not optimize away or cache reads/writes to that variable. It is commonly used for memory-mapped hardware registers and variables shared with interrupt handlers.

🏏

Cricket analogy: volatile is like telling a scorer never to trust their memory of the score and always re-check the physical scoreboard, because it can change unexpectedly from a DRS review outside the normal over-by-over flow.

Q: Why do header files use include guards like #ifndef/#define/#endif? A: Header guards prevent a header file's contents from being included more than once in the same translation unit, which would otherwise cause 'redefinition' compile errors for types, functions, or macros if the header is directly or indirectly included multiple times (common with nested #include chains). #pragma once achieves the same effect with non-standard but widely supported compiler-specific syntax.

🏏

Cricket analogy: Header guards are like a tournament rule ensuring a player can't be registered twice on the same team sheet even if nominated through multiple routes, preventing a 'duplicate player' conflict on match day.

Q: What is a dangling pointer, and how can it be avoided? A: A dangling pointer points to memory that has already been freed or that has gone out of scope (such as returning the address of a local variable from a function). Dereferencing it causes undefined behavior. It can be avoided by setting a pointer to NULL immediately after calling free() on it, and by never returning addresses of automatic (stack) local variables from a function.

🏏

Cricket analogy: A dangling pointer is like a fan still cheering for a player's old jersey number after it's been retired and reassigned, or referencing a substitute who already left the ground — set that reference to NULL after they exit.

4. Example

c
#include <stdio.h>

/* Demonstrates call-by-reference simulation using pointers */
void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

int main(void) {
    int x = 5, y = 10;
    printf("Before swap: x = %d, y = %d\n", x, y);

    swap(&x, &y);

    printf("After swap: x = %d, y = %d\n", x, y);
    return 0;
}

5. Output

text
Before swap: x = 5, y = 10
After swap: x = 10, y = 5

6. Key Takeaways

  • Arrays decay to pointers in expressions but differ in sizeof behavior and reassignability.
  • calloc() zero-initializes memory and checks for multiplication overflow; malloc() leaves memory uninitialized.
  • Pass-by-pointer is C's mechanism for simulating pass-by-reference, since C is strictly pass-by-value.
  • static at function scope preserves a variable's value across calls; static at file scope restricts linkage to that file.
  • Structure padding aligns members to natural boundaries, which can make sizeof(struct) larger than the sum of member sizes.
  • const restricts modification, volatile prevents compiler optimization on values that can change externally, and header guards prevent duplicate inclusion errors.

Practice what you learned

Was this page helpful?

Topics covered

#CProgrammingStudyNotes#Programming#CommonCInterviewQuestions#Common#Interview#Questions#Syntax#StudyNotes#SkillVeris#ExamPrep

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse