Common C Programming Errors: 10 Mistakes to Fix Before Interviews
Syntax errors, off-by-one array indexing, and missing semicolons are the C mistakes that derail placement coding rounds. Here is how to fix every one of them.
C has a short list of mistakes that most beginners make repeatedly, and placement coding rounds are designed to test whether you recognise them.
Every error here follows a pattern. Learn the pattern once and you won’t fall for it on paper, in an IDE, or in an MCQ that asks “what does this code print?”
Five Types of Errors in C
Before the examples, a taxonomy. C errors fall into five categories. Knowing which category you’re looking at tells you when it surfaces and how hard it is to find.
Syntax errors are caught by the compiler before the program runs. Missing semicolons, undeclared variables, mismatched braces: the compiler reports the line number. Annoying, but easy to fix.
Runtime errors happen while the program executes. Division by zero, file-not-found, and out-of-bounds memory access all compile fine, then crash or hang at runtime. The compiler cannot predict them.
Linker errors mean the code compiled but the linker cannot find a function or library it needs. Calling a function defined in another file without the right header is the classic example.
Logical errors are the quiet ones. The program compiles, runs to completion, and produces output, but it is the wrong output. No crash, no warning. You need test cases with known expected results to catch them.
Semantic errors are a subset of logical errors where the output has no meaningful relationship to what the program intended to compute. Both types require the same fix: trace through the logic manually or step through with a debugger.
The Mistakes That Show Up Most
Using = Instead of == in Conditionals
This is the most common beginner error in C, and it produces no syntax error.
/* Wrong: assignment in condition creates an always-true loop */
char x = 'Y';
while (x = 'Y') {
printf("Continue? (Y/N): ");
scanf(" %c", &x);
}
The while condition does not compare x to 'Y'. It assigns 'Y' to x and evaluates to the ASCII value of 'Y', which is non-zero. The loop never ends. The correct version:
/* Correct */
char x = 'Y';
while (x == 'Y') {
printf("Continue? (Y/N): ");
scanf(" %c", &x);
}
GCC’s -Wall flag warns about assignment-in-condition. Enable it.
Off-by-One Array Indexing
C arrays start at index 0. An array declared as int array[10] has valid indices array[0] through array[9]. Writing to array[10] is undefined behavior: the compiler won’t stop you, and the results are unpredictable.
/* Wrong: accesses array[10], which is out of bounds */
int array[10];
for (int i = 1; i <= 10; i++)
printf("%d\n", array[i]);
/* Correct */
int array[10];
for (int i = 0; i < 10; i++)
printf("%d\n", array[i]);
Placement MCQs routinely present the wrong version and ask what happens. The answer is undefined behavior: not a segfault, not garbage, not zero. Undefined.
Misplaced Semicolons After Loop Headers
A semicolon right after a for or while header terminates the statement immediately, creating an empty loop body.
/* Wrong: semicolon ends the for loop; printf runs once after the loop */
int x;
for (x = 0; x < 100; x++);
printf("%d\n", x);
/* Correct */
int x;
for (x = 0; x < 100; x++)
printf("%d\n", x);
The wrong version prints 100 exactly once. The indentation makes it look intentional. This is a favourite MCQ trap.
Undeclared Variables and Functions
Every variable must be declared before use. Every function called before its definition needs a forward declaration.
/* Wrong: x is used without being declared */
int main() {
scanf("%d", &x);
printf("%d\n", x);
return 0;
}
/* Correct */
int main() {
int x;
scanf("%d", &x);
printf("%d\n", x);
return 0;
}
For functions: if menu() is defined after main(), add void menu(); as a forward declaration before main().
Missing & in scanf
scanf requires the address of the variable, not the variable’s value.
/* Wrong: passes the value of n (uninitialised), not its address */
int n;
scanf("%d", n);
/* Correct */
int n;
scanf("%d", &n);
The wrong version is undefined behavior. On most systems it crashes, but -Wall will warn about it.
Missing Braces in Multi-Statement Loops
Without braces, a for or if block applies to exactly one statement.
/* Wrong: only sum1 uses the loop; sum2 accumulates outside */
int i, sum1 = 0, sum2 = 0;
for (i = 1; i <= 10; i++)
sum1 = sum1 + i;
sum2 = sum2 + i * i;
printf("%d %d\n", sum1, sum2);
/* Correct */
int i, sum1 = 0, sum2 = 0;
for (i = 1; i <= 10; i++) {
sum1 = sum1 + i;
sum2 = sum2 + i * i;
}
printf("%d %d\n", sum1, sum2);
Indentation can make the wrong version look correct at a glance.
Operator Precedence Mistakes
Assignment has lower precedence than comparison in C. This catches students who expect (value = product()) to evaluate before the comparison.
/* Wrong: >= binds before =; value becomes 1 or 0 (the bool result) */
if (value = product() >= 100)
tax = 0.05 * value;
/* Correct: extra parentheses force assignment first, then comparison */
if ((value = product()) >= 100)
tax = 0.05 * value;
Uninitialized Variables
Declaring a variable without initialising it leaves its value as whatever bytes happen to be in that memory location.
/* Wrong: count starts at an unknown value; the loop may never run */
int count;
while (count < 100) {
printf("%d\n", count);
count++;
}
/* Correct */
int count = 0;
while (count < 100) {
printf("%d\n", count);
count++;
}
For a deeper set of conceptual questions that cover type behaviour and memory, see must-solve conceptual C questions.
How Placement Coding Tests Use These Errors
Technical screens and aptitude tests use two formats for these errors. The first is an MCQ showing code with one of the bugs above, asking for the output or which line causes the error. The second is a coding round where the evaluator checks edge cases that trigger off-by-one or uninitialized-variable bugs.
The most effective practice: take the wrong version of each example, predict what happens, then compile and run to verify. If your prediction matches the output, you understand the error.
FACE Prep’s 31 most-asked C programming interview questions covers the specific program patterns that appear most in technical rounds at service and product companies. For pattern-printing programs that test loop control and nested iteration, most-asked C programs in interviews has the complete set.
One Habit That Prevents Most of These
Enable compiler warnings. Running gcc -Wall -Wextra -o output file.c activates the GCC warning flags that surface assignment-in-condition, uninitialised variables, and missing & in scanf. Most of the errors in this article generate a warning with -Wall enabled. Most students don’t enable it.
Reading compiler warnings before reading program output is a habit worth more than memorising any checklist.
C programs with undefined behavior from array overruns are exactly the kind of programs an AI can trace through step by step, explaining what the compiler sees versus what the programmer intended. TinkerLLM at ₹299 gives you that interactive debugging conversation: paste the wrong version of the off-by-one loop above, ask why it produces unexpected output, and get a line-by-line explanation faster than waiting for a Stack Overflow thread.
Primary sources
Frequently asked questions
What is the most common error in C programming?
Using = instead of == inside a conditional is the most widespread beginner mistake. It assigns a value rather than comparing, which creates an always-true or always-false condition.
What is the difference between a syntax error and a runtime error in C?
A syntax error violates C grammar rules and is caught by the compiler before the program runs. A runtime error occurs during execution, such as dividing by zero or accessing out-of-bounds memory.
What causes a segmentation fault in C?
A segmentation fault occurs when your program reads or writes memory it does not own. Common causes include out-of-bounds array access, dereferencing a NULL pointer, and writing to read-only memory.
Why does my for loop in C produce no output?
A semicolon immediately after the for-loop header creates an empty loop body. The loop completes without doing anything; the block that follows runs only once, outside the loop.
What does undeclared identifier mean in C?
The compiler cannot find a declaration for a variable or function name you used. Either the variable was never declared, or the function is defined after main without a forward declaration at the top of the file.
What is the difference between a logical error and a semantic error in C?
A logical error produces wrong but meaningful output; the program runs and computes something, just not the right thing. A semantic error produces output with no meaningful relationship to the intended computation.
A self-paced playground for building with LLMs.
TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.
Try TinkerLLM (₹299 launch)