Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » C programming language

C programming errors



In this article, we are going to learn some of the C programming language errors and their causes, solutions.
Submitted by Sudarshan Paul, on June 25, 2018

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.






Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates



© https://www.includehelp.com (2015-2018), Some rights reserved.