Back to C Notes
Topic #87

C Errors


Errors

Even experienced C developers make mistakes. The key is learning how to spot and fix them!

These pages cover common errors and helpful debugging tips to help you understand what's going wrong and how to fix it.


Common Compile-Time Errors

Compile-time errors are mistakes that prevent your program from compiling.

  1. Missing semicolon:

Example

#include <stdio.h>

int main() {
  int x = 5
  printf("%d", x);
  return 0;
}
  1. Using undeclared variables:

Example

#include <stdio.h>

int main() {
  printf("%d", myVar);
  return 0;
}
  1. Mismatched types (e.g. assigning a string to an int):

Example

#include <stdio.h>

int main() {
  int x = "Hello";
  return 0;
}

Common Runtime Errors

Runtime errors occur when the program compiles but crashes or behaves unexpectedly.

  1. Dividing by zero:

Example

#include <stdio.h>

int main() {
  int x = 10;
  int y = 0;
  int result = x / y;
  printf("%d\\n", result);  // not possible
  return 0;
}
  1. Accessing out-of-bounds array elements:

Example

#include <stdio.h>

int main() {
  int numbers[3] = {1, 2, 3};
  printf("%d\\n", numbers[8]);  // element does not exist
  return 0;
}
  1. Using freed memory:

Example

#include <stdio.h>
#include <stdlib.h>

int main() {
  int* ptr = malloc(sizeof(int));
  *ptr = 10;
  free(ptr);
  printf("%d\\n", *ptr); // Undefined behavior - accessing memory that was freed
  return 0;
}

Good Habits to Avoid Errors

  • Always initialize your variables
  • Use meaningful variable names
  • Keep your code clean and use indentation to stay organized
  • Keep functions short and focused
  • Check if loops or conditions are running as expected
  • Read error messages carefully - they often tell you exactly where the problem is

In the next chapter, you will learn how to debug your code - how to find and fix bugs/errors in your C program.

Want to go beyond the notes?

Join Coding Now Tech Institute's C course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

C Errors – FAQs

Quick answers about learning C Errors in C.

This free note from Coding Now Tech Institute explains C Errors in C — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every C topic on Coding Now Tech Institute, including C Errors, is 100% free with no signup required.
With focused practice, most students grasp C Errors in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now