C Aptitude Questions and Answers for Interview Preparation

C aptitude questions test how well you understand the C language at a deep level — not just syntax, but behavior at the edges: undefined behavior, pointer arithmetic, operator precedence, and type conversion. These questions appear in technical interviews at companies hiring for systems programming, embedded software, and firmware roles.

This page collects 31 sets of C aptitude questions with answers and detailed explanations. Each set contains 5–10 “predict the output” questions covering pointers, arrays, storage classes, preprocessor, and more.

Topics Covered

  • Pointers & arrays — pointer arithmetic, array decay, pointer to const, double pointers
  • Operators — precedence, associativity, pre/post increment, bitwise operators
  • Storage classes — auto, static, extern, register and their scope/lifetime
  • Type conversions — implicit promotions, signed/unsigned, float vs double precision
  • Preprocessor — macro expansion, token pasting, stringification
  • Undefined & implementation-defined behavior — the tricky cases that trip up even experienced programmers
  • Strings — string literals, strcpy, strlen, null terminator edge cases
  • Memory — stack vs heap, sizeof, struct padding, memory leaks

Sample C Aptitude Questions

These six questions illustrate the style and difficulty of the full sets below.


Question 1 — Pointer to const

#include <stdio.h>
int main(void) {
    const int x = 5;
    int *p = (int *)&x;
    *p = 10;
    printf("%d\n", x);
    return 0;
}

Answer: Undefined behavior. x is declared const. Casting away the const qualifier and writing through the pointer violates the C standard. Most compilers print 5 (the original value from read-only storage), but the result is not guaranteed.


Question 2 — Array indexing equivalences

#include <stdio.h>
int main(void) {
    char s[] = "abc";
    printf("%c %c %c\n", s[1], *(s+1), 1[s]);
    return 0;
}

Answer: b b b. In C, a[i] is defined as *(a + i). Because addition is commutative, *(i + a) is identical, and i[a] is just another way to write it. All three expressions refer to the same byte.


Question 3 — Float vs double comparison

#include <stdio.h>
int main(void) {
    float  f = 1.1f;
    double d = 1.1;
    if (f == d)
        printf("equal\n");
    else
        printf("not equal\n");
    return 0;
}

Answer: not equal. float stores 1.1 with 7 significant digits of precision; double stores it with 15–16. The two binary representations differ, so == is false. Rule: never compare floating-point values with ==.


Question 4 — String literal modification

#include <stdio.h>
int main(void) {
    char *s = "hello";
    s[0] = 'H';
    printf("%s\n", s);
    return 0;
}

Answer: Undefined behavior (usually a segfault). String literals are stored in read-only memory. char *s = "hello" makes s point into that read-only region. To get a modifiable copy, use char s[] = "hello" instead.


Question 5 — sizeof a function parameter

#include <stdio.h>
void print_size(int a[10]) {
    printf("%lu\n", sizeof(a));
}
int main(void) {
    int arr[10];
    print_size(arr);
    return 0;
}

Answer: 8 (on a 64-bit system), not 40. When an array is passed to a function, it decays to a pointer. Inside print_size, a is int *, not int[10], so sizeof(a) gives the pointer size.


Question 6 — Static variable in a function

#include <stdio.h>
void counter(void) {
    static int n = 0;
    n++;
    printf("%d\n", n);
}
int main(void) {
    counter();
    counter();
    counter();
    return 0;
}

Answer: 1, 2, 3. A static local variable is initialized only once (at program start) and retains its value between calls. It lives in the data segment, not the stack.


All C Aptitude Question Sets

Each set contains 5–10 questions in “predict the output or error” format with full explanations.

How to Use These Questions

  • For freshers: Work through Sets 1–10 first. These cover the core language features tested in campus placements and entry-level interviews.
  • For experienced candidates: Focus on Sets 11–31 — struct layout, function pointers, undefined behavior, and preprocessor edge cases.
  • Practice method: Try to predict the output before reading the answer. Write it down, then verify. This builds the mental model faster than passive reading.

Related Resources


As an Amazon Associate we earn from qualifying purchases.

Recommended Book

The questions on this page are grounded in The C Programming Language by Kernighan & Ritchie — the definitive reference for anyone preparing for a C interview. Also on Amazon.com.