C Language Concepts Interview Questions and Answers: Model Answers, Code Traces and Traps
Prepare for C interviews by learning how to explain types, aliases, arrays, storage and allocation, then trace exact values without inventing output for invalid code.
KnowledgeGate Team
Exam prep & CS education

Memorising that C has pointers, arrays and static variables may survive the first interview prompt. The next prompt may change one argument, ask which object changes, or present code with no honest output. Strong answers pair concise definitions with exact value, alias and lifetime traces. Its central call starts with x = 4, y = 7 and nums = {2, 5, 8}, but changes only y and nums[1]. Interviewers may mix fundamentals-first prompts with depth-oriented follow-ups.
1. What is C, and what happens before a C program runs?
What is C? C is a general-purpose procedural language with statically typed expressions, functions, arrays, structures and explicit address manipulation through pointers. It gives close control over representation and lifetime, but does not standardise every machine size, evaluation order or invalid access.
What is the usual path from source file to executable? A common model is preprocessing -> compilation -> assembly -> linking: handle directives and macros, translate the language, produce object code, then resolve symbols and combine objects or libraries. This is a common toolchain model, not a C guarantee.
How does a declaration differ from a definition? extern int total; declares an object without defining it in that translation unit; int total = 0; defines it. int add(int, int); declares a function; int add(int a, int b) { return a + b; } defines it. The distinction matters when a linker reports a missing definition.
2. How do types and operands decide a result before assignment?
Is an int always four bytes? No. C guarantees sizeof(char) == 1, while CHAR_BIT gives the bits in that byte. Sizes and ranges of other integer types depend on the implementation. sizeof returns size_t, so query a type instead of reciting one platform's table.
Why does double first = 7 / 2; store 3.0? Both operands are int, so 7 / 2 = 3 finishes before assignment converts it to double 3.0. In double second = 7 / 2.0;, 2.0 is double, so 7 converts before division and the result is 3.5. A destination type cannot retroactively change a completed operation.
For int values[4] = {3, 6, 9, 12};, sizeof values / sizeof values[0] equals 4 in the array's declaring scope, without assuming an int byte size. The parameter exception appears next.
3. Fully worked call trace: value copy, pointer mutation and array adjustment
Does C support call by reference? Predict the output and explain every changed object. Consider this fragment:
void adjust(int value, int *alias, int nums[3]) {
value += 10;
*alias += 5;
nums[1] = nums[0] + nums[2];
}
int main(void) {
int x = 4, y = 7, nums[3] = {2, 5, 8};
adjust(x, &y, nums);
printf("%d %d %d %d %d\n", x, y, nums[0], nums[1], nums[2]);
}Trace the parameter copies:
Copy | Operation | Caller after return |
|---|---|---|
|
|
|
|
|
|
|
|
|
The exact output is 4 12 2 10 8. C passes every argument by value, pointers included; indirection can modify the caller's object. Parameter int nums[3] adjusts to int *nums, so sizeof nums / sizeof nums[0] compares pointer and element sizes, not array length.
For a dedicated three-way comparison of value, address and C++ reference parameters, see Call by Value, Address and Reference Interview Questions with Answers; this page owns the mixed C trace where a copied pointer mutates an array and a scalar.

4. Are arrays pointers, and is a string literal a character array?
Is an array the same thing as a pointer? No. An array is a fixed sequence of elements. Its name often converts to a pointer to the first element, but not as the operand of sizeof or unary &, or when a string literal initializes an array.
For int data[4] = {10, 20, 30, 40}; int *p = &data[1];, p[-1] is 10, *p is 20, and *(p + 2) is 40. data + 4 is a valid one-past pointer but cannot be dereferenced.
How do char word[] = "cat"; and const char *label = "cat"; differ? word is the four-element array {'c', 'a', 't', '\0'}. Thus sizeof word = 4, strlen(word) = 3, and word[0] = 'b' validly makes "bat". label points at a string literal. sizeof label is the pointer object's size, not the text length. The literal must not be modified; removing const does not make label[0] = 'b' valid, and that write has undefined behaviour.
For narrower treatments, Relationship Between Arrays and Pointers Interview Questions: Model Answers in C owns address and 2D-array comparisons, while Character Pointer and String Interview Questions in C: Answers with Memory Traces owns character-pointer memory and operator-precedence traces. This page uses arrays to explain parameter adjustment and string-literal mutability inside a broader C-concepts answer.
Name the object first, then check conversion, bounds and mutability.
![Comparison shows mutable char word[] storing cat and const char *label pointing to a read-only literal, with sizes four and pointer size.](https://cdn.knowledgegate.ai/blog-assets/blog_asset_1786796147319_uisoi5.jpg)
5. Scope, storage duration and linkage answer three different questions
How are scope, storage duration and linkage different? Scope says where a name is visible, storage duration says how long its object exists, and linkage says whether declarations denote the same entity.
int next(void) {
int step = 3;
static int count = 2;
count += step;
return count;
}
int main(void) {
int first = next(), second = next();
}step is recreated as 3 per call. count is initialized once and changes 2 -> 5 -> 8, so first = 5 and second = 8. Its name has block scope, while its object has static storage duration.
File-scope static int cache; has internal linkage. A compatible extern int shared; can name an externally linked definition elsewhere. In int *bad(void) { int n = 9; return &n; }, leaving the function ends n's lifetime, so later dereferencing the returned pointer has undefined behaviour.
6. Dynamic allocation questions are ownership and lifetime questions
What does malloc return, and what must correct code do next? Use int *scores = malloc(3 * sizeof *scores);. Check scores != NULL, then assign scores[0] = 4, scores[1] = 9, scores[2] = 16. Their total is 4 + 9 + 16 = 29. sizeof *scores follows the pointed type without hard-coding an int byte count.
What changes after free(scores)? The allocation's lifetime ends, so scores and copied aliases must not be dereferenced. free rewrites no pointer. free(scores); scores = NULL; clears one owner variable, but an earlier int *alias = scores; remains dangling.
Repair root causes: initialize pointers, check allocation failure, release each owned allocation once, and keep the object alive through its final access. A null check excludes only null, not an uninitialized or non-null dangling pointer. Undefined access need not crash or print garbage.
7. How interviews turn a definition into a depth ladder
Build depth in three rungs. First, explain 7 / 2 = 3 and distinguish an array from a pointer. Second, trace adjust(x, &y, nums) to 4 12 2 10 8. Third, reset x = 4, y = 7, nums = {2, 5, 8} and call adjust(x, &x, nums): local value becomes 14, caller x changes 4 -> 9, y stays 7, and the array becomes {2, 10, 8}. Output: 9 7 2 10 8.
Can every C output question be answered numerically? No. 7 / 2 = 3 is defined. Plain char range is implementation-defined. Evaluation order in f() + g() is unspecified when no stronger sequencing rule applies. i = i++ + 1, dereferencing bad()'s returned pointer, and modifying a string literal have undefined behaviour. Never invent output for undefined code.
Use four passes: identify types, objects and lifetimes; mark conversions, decay and aliases; trace values; classify behaviour. Explain the passes aloud, then test them against a fresh code fragment.
8. C language concepts in 60 seconds, then the next step
The short version: declarations introduce names; definitions create objects or bodies; operand types act before assignment; C passes by value; arrays often decay but are not pointers; literals are not writable; scope, lifetime and linkage differ; and invalid lifetime or unsequenced modification has no honest output.
Without notes, reproduce 7 / 2 -> 3, 7 / 2.0 -> 3.5, 4 12 2 10 8, 9 7 2 10 8, static returns 5, 8, and total 29. Continue with the C Language Course, or browse the Placement Preparation & Coding: Exams, Eligibility & Courses.
Keep learning
Key Features of the C Programming Language: Code Examples
What do C's features actually do in a program? Follow an even-number sum and a pointer update, then test your understanding with small code changes.
C Compilation Model Tutorial: From Source Code to Executable
See what GCC does between a readable C file and a running program. Trace one two-file project through every build stage, diagnose failures, and test your understanding.
Merge Sort Interview Questions and Answers: Traces, Complexity, and Code
Prepare crisp merge sort interview answers through a fully traced array, boundary-safe Java implementation, complexity proof, stability example, and inversion-count follow-up.
Iterative Loops in C for GATE: Code Traces, Worked Examples and Exam Traps
Learn a mechanical method for tracing C loops. Work through exact values, invariants, nested-loop counts, complexity, termination bugs, and output traps.





