Let us see what are the most common errors in programming and how to resolve them easily with simple tweaks in no time.
These errors are applicable to almost all the programming languages but we’ve explained here using C programming language. There are some specific types of errors in programming that you must know.

1. Improper Comment Characters
There are two methods of commenting allowed in C programming. The first way to comment is to create single line comments with must start with two slashes //.
The other way is to create comments that can spread over multiple lines in a program. It starts with a /* and must be terminated by */ symbol.
We usually tend to forget to terminate the comment and it causes an error in the C program. Please see an example of commenting in C programming.
1 2 3 4 5 6 7 8 9 10 | #include<stdio.h> int main() { printf("Hello World\n"); /*This is a multi-line comment*/ return 0; //This is a single-line comment. } |
2. Undeclared Variables and Functions
Every user-defined function that is called must be defined with the function prototype above the main function before it is declared which is one of most common mistakes in C programming.
In the function prototype, we have to declare the number of arguments and their datatype. We usually forget to pass appropriate variables within the function parameters. You must check the C function pointer as programmers usually make mistakes here.
Another mistake is the undeclared variables. here, we have used b but we haven’t defined and initialized the variable which will generate a compile time error.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include<stdio.h> int main() { int a = 0; printf("Enter value for a:\t"); scanf("%d", &a); printf("Enter value for b:\t"); scanf("%d", &b); // Variable Not Defined sum_function(a); //Improper Function Parameters return 0; } void sum_function(int a, int b) // Function Prototype Undefined Above Main() Function { int c = a + b; printf("Value for c: %d", c); } |
3. Missing Braces and Indentations
It is very common to forget closing braces when coding with nested loops. It is a compile time error usually but sometimes also turn out to be a run-time error.
With looping statements such as for loop and while loop, the braces must be defined correctly to define the scope and visibility of the for loop.
In the following code, there are two statements after the for loop which creates ambiguity as to which statement should be calculated with the for loop.
If both of them needs to be included within the for loop, then braces must be defined. Otherwise, a simple indentation can signal the compiler that only the first statement after the for loop needs to be included.
1 2 3 4 5 6 7 8 9 10 | #include<stdio.h> int main() { int a = 0; for(a = 0; a < 5; a++) a = a + 7; // No Braces Defined a = a - 2; // Should Be Intended Properly return 0; } |
4. Improper use of Semicolon
Every C programming statement must end with a semicolon. It is very common to forget a semicolon and it may cause misleading errors and could be time consuming to debug the code.
The improper use of semicolons can also cause considerable compilation issues.
1 2 3 4 5 6 7 8 9 10 11 12 | #include<stdio.h> int main() { int a = 0 //Semicolon Undefined while(i < 5); //Improper Use Of Semicolon { printf("Hello World"); i++; } return 0; } |
5. Missing and Improper Quotations
It is very likely to happen that a programmer may use single quotes (‘ ‘) instead of double quotes (” “) or vice versa.
A character in a string is defined with single quotations whereas a string is defined with double quotes and it is very much important to keep track of it.
1 2 3 4 5 6 7 8 9 | #include<stdio.h> int main() { char demo_character = 'C'; //Character Definition char demo_string[20] = "CodingAlpha"; //String Definition printf("Character:\t%c", demo_character); return 0; } |
7. Array Bounds Issue
The indexes in C programming starts with 0. Sometimes, we do not pay attention towards the looping condition and we get a run time error which can create confusion.
A common mistake here is to start the looping with an index 1 which may give a wrong output if the condition is not used properly. This is another very common programming error in many of the programming languages.
1 2 3 4 5 6 7 8 9 10 11 12 | #include<stdio.h> int main() { int count, sum = 0; for (count = 1; count < 10; count++) //The index should start from 0 { sum = sum + 1; } printf("Count: %d", count); //This will result to 9 return 0; } |
8. Missing Operators in scanf and printf functions
In a scanf() function, all the non pointer variables must be preceded by an Ampersand & operator. It is a very common mistake in C programming, and can cause confusions as it is not always detected by the compiler.
The & operator is reference operator and helps to scan the user input and assign it to a placeholder or a variable.
1 2 3 4 5 6 7 8 9 | #include<stdio.h> int main() { int num1, num2; printf("\nEnter the first number:\t"); scanf("%d", num1); //Ampersand & Operator Undeclared return 0; } |
9. Operator Precedence
Mathematical expressions are an integral part of C programming language. We normally tend to do mistakes in our mathematical formulas by applying wrong sequence of operators.
The operator precedence defines the way how an expression will be evaluated by the C compiler and must be followed. This is similar to the BODMAS rule.
This creates ambiguity in the the resultant value of the expression but it can be easily prevented by using parantheses.
1 2 3 4 5 6 7 8 9 | #include<stdio.h> int main() { int num1 = 5; int result = num1 * 5 + 7 - 9 / 8; //Improper Result printf("Result: %d\n", result); return 0; } |
10. Improper Use of Increment and Decrement Operators
The increment and decrement are one of the most commonly used operators in C programming and these operators produce a lot of errors if not used properly.
The increment/decrement operators are logical operators and hence will never be traced by the compiler as it comes under logical error and can produce wrong output.
It is important to understand the use of both pre and post increment/decrement operators before using them in your expressions.
1 2 3 4 5 6 7 8 9 | #include<stdio.h> int main() { int num = 5; num = num++ + ++num + num-- + --num; //Improper Use of Operators printf("Result: %d\n", num); return 0; } |
11. Infinite Loops
The infinite loop or indefinite loop creates one of the most common errors in C programming language. These kinds of errors generally occur in loops.
Every loop has to repeat steps until a certain condition is met. It is important for the condition to satisfy else the loop will keep on till infinity.
To prevent infinite loop condition, there should be an increment or decrement operator which will help to satisfy the looping condition.
1 2 3 4 5 6 7 8 9 10 11 12 | #include<stdio.h> int main() { int num = 0; while(num < 5) { printf("Count = %d", num); num++; //Used To Increment 'num' to satisfy the condition } return 0; } |
12. Datatype mismatch
The datatype mismatch error occurs during function prototype definitions, passing arguments to a function, variable declarations and much more.
These kinds of errors also occur while passing parameters to a user-defined function as shown above.
1 2 3 4 5 6 7 8 | #include<stdio.h> int main() { int num = 10; printf("Number:\t%f", num) //Wrong Format Specifier return 0; } |
13. Divide by Zero
This is probably the most common errors in C programming by newbie programmers.
When you divide any number by zero, it will result in a compile time error and will not let you run the C program.
1 2 3 4 5 6 7 8 9 | #include<stdio.h> int main() { int num = 10; int result = num/0; //Divide By Zero printf("Result:\t%f", result); return 0; } |
Another very common error in C programming is the Lvalue Required Error.
These were some of the most common programming mistakes in C programming and is also applicable to C++ programming language.
If you have any doubts or have any common errors in C programming that you have faced in your programming journey, let us discuss in the comment section below.
Thank you so much for the solutions to these common programming errors. Datatype error was the one I used to get very frequently.
What is segmantation default
where is the 6th mistake ? hahahahaha!!