Errors In C Programming ?

Prashant | Sun, 14 Jun, 2020 | 136

C programming errors

In this tutorial we will learn that what is error in C programming or normal programming, and how does it occur and how to rectify it ?

Making errors in C programming is the most elementary step towards developing your grip in the subject. You must know the proper debugging tips and tricks to identify the error. As a beginner in C you might have encountered many of them and with the basic knowledge you can obviously find the errors and finish the compilation of your program successfully. Here we will mention some common errors that beginners in C language commit and ways to tackle them.

Compile time error

The errors occurring during the compilation of a program leading to failure in the compilation are termed as compile time error. They are generally caused when the programmer does not follow the programming rules.

Run time error

These errors generally occur due to the incorrect logic used while programming. They are difficult to detect as compared to compile time errors. The programmer must check the code from the beginning in order to check where the logic is wrong.

Warnings

The warnings are generated by the compiler when the compiler detects some abnormality in the coding way or pattern. The program might occasionally crash or misbehave if warnings are neglected but that rarely occurs. In C warnings can be neglected but compiler errors and runtime errors should be corrected to obtain the desired output.

Some of the errors, their causes

1) Undeclared Variables

int main()
{
	if(x>5)
		printf("x is greater than 5\n");
}

The variable x used, is undeclared in the function. Hence compiler is not aware of any such variable.

2) Uninitialized variables

int lc;
while(lc<100)
{
	lc++;
}

The loop counter (lc) used with the while loop is not initialized. It is compulsory to initialize the loop counter before using while loop. Hence the compiler will not enter the loop.

3) Using assignment operator (=) to check equality

char x='Y';

while(x='Y')
{
	printf("x is equal to y\n");
}

Here, in the while loop condition x is assigned to y with a single equal to sign which is wrong. In order to check equality == sign should be used.

4) Incorrect use of semicolon

int main()
{
	int a = 0 //Semicolon Undefined
	while(i < 5);
	{
		printf("Hello World");
		i++;
	}
	return 0;
}

In the above cod snippet, the while loop has been terminated with a semicolon which is undesirable. Loop statements are never terminated with a semicolon. Therefore the loop body doesn't get executed.

5) Missing operator in scanf function

#include<stdio.h>

int main()
{
	int num1, num2;
	printf("\nEnter the first number:\t");
	scanf("%d", num1); 
	return 0;
}

In the above case, & ampersand operator is not used in the scanf function. The compiler will successfully compile the program with no errors. But during runtime the user will not be able to give the input to the program. This is a very common mistake that beginners make.

 

 

 

 

 

 

Related Articles :- 

1Introduction And Getting Started With C

2Basic Of C Language

3. Why We Should Use C Language

4. Applications Of C Programming

5. Basic Rules For Writting C Program

6. Keywords In C Language

7. Comments In C Programming

8. Tokens In C

9. Difference Between Int Main And Void Main

10. C Processor And Macros

11. Variables In C

12. Types Of Variables In C

13. Difference Between Local And Global Variable

14. Difference Bwtween Auto / Extern / Static Variable

15. Constant In C

16. How To Access Global Variable Using Extern Keyword In C

17. Exit And Return Staterment In C

18. Print Float Value Upto N Decimals In C Programming

19. How To Print Multiline Message Using Single Printf In C Programming ?

20. What Value Returned By Scanf Function In C Language ?

21. What Value Is Returned By Printf And Scanf In C

22. What Do 'Lvalue' And 'Rvalue' Mean In C/C++?

23. Errors In C Programming ?

0 comments
Leave a comment