Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Errors in C Programming

The document outlines four types of errors in C programming: syntax errors, semantic errors, logic errors, and run-time errors. Syntax errors occur when code violates grammatical rules, while semantic errors arise from logical inconsistencies despite correct syntax. Logic errors lead to flawed program behavior, and run-time errors happen during execution due to resource issues or unexpected inputs.

Uploaded by

jordenpayments
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Errors in C Programming

The document outlines four types of errors in C programming: syntax errors, semantic errors, logic errors, and run-time errors. Syntax errors occur when code violates grammatical rules, while semantic errors arise from logical inconsistencies despite correct syntax. Logic errors lead to flawed program behavior, and run-time errors happen during execution due to resource issues or unexpected inputs.

Uploaded by

jordenpayments
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Errors in C Programming

 Syntax Errors:
These are errors that occur when the code does not follow the grammatical rules of
the programming language.
 Examples:
 Missing parentheses or brackets.
 Using an incorrect keyword (e.g., "prin" instead of "print").
 Incorrectly formatted code (e.g., missing semicolons).

 Semantic Errors:
These errors occur when the code is syntactically correct but does not make sense in
the context of the language's rules or the programmer's intended logic.
 Examples:
 Using an undeclared variable.
 Trying to perform an operation on incompatible data types.
 Calling a function with the wrong number or type of arguments.

 Logic Errors (or Bugs):


These errors occur when the code is syntactically correct and semantically valid, but
the program's logic is flawed, leading to incorrect or unexpected behavior.

 Example: An algorithm that incorrectly calculates a result, a loop that runs forever, or a
program that doesn't handle certain inputs correctly.

 Run-time Errors
 A runtime error happens during the execution of a program, meaning the code has been
compiled or interpreted and is running, but something goes wrong.

 Causes:
 Resource issues: The program might run out of memory, disk space, or other system
resources.
 Unexpected input: The program might receive data or instructions it wasn't designed to
handle.
 Logic errors: The program's logic might lead to an error, such as dividing by zero or
accessing an invalid memory location.
 External factors: Problems with hardware, network, or other software can also cause
runtime errors.

 Examples:
 Division by zero: Attempting to divide a number by zero.
 Array out of bounds: Trying to access an element of an array that doesn't exist.
 Null pointer exception: Trying to access a variable that hasn't been assigned a value.
 File not found: Trying to open a file that doesn't exist.
 How to handle them:

You might also like