0% found this document useful (0 votes)
157 views20 pages

Errors+Flow Charts

The document discusses different types of errors in C programming: runtime errors which occur during program execution due to illegal operations, compile errors which happen during compilation due to syntax or semantic issues, and logical errors which cause incorrect program output. It also describes linker errors which occur when needed functions cannot be found, and provides examples of each error type. Programming methodology, algorithms, and flowcharts are defined to help explain programming concepts and solutions to problems. Common control structures like if-else, switch-case, and for loops are explained through flowcharts and code examples.

Uploaded by

Erick W Daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views20 pages

Errors+Flow Charts

The document discusses different types of errors in C programming: runtime errors which occur during program execution due to illegal operations, compile errors which happen during compilation due to syntax or semantic issues, and logical errors which cause incorrect program output. It also describes linker errors which occur when needed functions cannot be found, and provides examples of each error type. Programming methodology, algorithms, and flowcharts are defined to help explain programming concepts and solutions to problems. Common control structures like if-else, switch-case, and for loops are explained through flowcharts and code examples.

Uploaded by

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

Errors in C

• While writing c programs, errors also known as bugs in


the world of programming may occur unwillingly which
may prevent the program to compile and run correctly
as per the expectation of the programmer.
• Basically there are three types of errors in c
programming:
1. Runtime Errors
2. Compile Errors
3. Logical Errors
4. Linker Errors
C Runtime Errors
• C runtime errors are those errors that occur
during the execution of a c program and generally
occur due to some illegal operation performed in
the program.
• Examples of some illegal operations that may
produce runtime errors are:
• Dividing a number by zero
• Trying to open a file which is not created
• Lack of free memory space
Compile Errors
Compile errors are those errors that occur at the time of compilation of the program. C compile
errors may be further classified as:
Syntax Errors
When the rules of the c programming language are not followed, the compiler will show syntax
errors.
For example, consider the statement,
int a,b:
The above statement will produce syntax error as the statement is terminated with : rather than ;
Semantic Errors
Semantic errors are reported by the compiler when the statements written in the c program are
not meaningful to the compiler.
For example, consider the statement,
b+c=a;
In the above statement we are trying to assign value of a in the value obtained by summation of b
and c which has no meaning in c. The correct statement will be
a=b+c;
Logical Errors
Logical errors are the errors in the output of the
program. The presence of logical errors leads
to undesired or incorrect output and are
caused due to error in the logic applied in the
program to produce the desired output.
Also, logical errors could not be detected by the
compiler, and thus, programmers has to check
the entire coding of a c program line by line.
Linker Errors
• If you receive a linker error, it means that your code compiles
fine, but that some function or library that is needed cannot
be found. This occurs in what we call the linking stage and
will prevent an executable from being generated. Many
compilers do both the compiling and this linking stage.
• Example 1: You misspell the name of a function (or method)
when you declare, define or call it:
• void Foo(); int main() { Foo(); return 0; } void foo() { // do
something } so that the linker complains:
somefile.o(address): undefined reference to `Foo(void)' that
it can't find it.
PROGRAMMING METHODOLOGY
A computer program is used to a solve a problem. The steps
involved are:
1. Analyze the problem
2. Identify the variables involved
3. Design the solution
4. Write the program
5. Enter it into a computer
6. Compile the program and correct errors
7. Correct the logical errors if any
8. Test the program with data
9. Document the program
Algorithms
Step by step procedure for solving a problem
Example
To make a coffee
Step1: Take proper quantity of water in a cooking pan
Step2: Place the pan on a gas stow and light it
Step3: Add Coffee powder when it boils
Step4: Put out the light and add sufficient quantity of sugar and
milk
Step5: Pour into cup and have it.
To add two numbers
Step1: Input the numbers as x, y
Step2: sum=x + y
Step3: print sum
For a better understanding of an algorithm, it is represented pictorially.
The pictorial representation of an algorithm is called a Flow Chart. For
this certain pictures are used.
A flow-chart story

 A graphical representation of an algorithm.


 Drawn using certain symbols such as rectangles,
diamonds, ovals, and small circles.
 These symbols are connected by arrows called
flow lines.
 Flow-charts clearly show the program's
execution order and indirectly describe how
control structures operate.
Symbol Name Description

A process or an action such as


Rectangular or action
calculation and assignment

Begin/start or End/stop. Indicates a


Oval
completed algorithm or program flow
Indicates a decision to be made such
Diamond or decision as YES/NO, TRUE/FALSE, <, <= etc.

Indicates the order of the actions to be


Flow lines
executed, connecting other symbols
Indicates a portion of a complete
algorithm continued from the previous
Small circle or connector
portion or to be continued to the next
portion

The input or output such as standard


Input or output
input or output
PROGRAM CONTROL
 The following flow chart examples represent C if selection constructs.

Start

printf("");

scanf("”);

TRUE
intNum ==
3? printf("");
printf("");

FALSE

printf("");

The if program source code exa


mple describing flow chart
Stop
PROGRAM CONTROL
Start

printf("");  The following flow chart


printf("");
examples represent C
switch-case selection
scanf("");
constructs.
T
B? break;
printf("");

G?

R?
The switch-case-break
program source code e
T xample
T printf("");
Y? break;
printf("");
F

printf("");

Stop
PROGRAM CONTROL
 if, if-else and switch-case-break flow charts
PROGRAM CONTROL
 The for loop flow chart should be something like the following.
Start

Evaluate initial_value

Do increment/ decrement

Evaluate
condition(s) Execute statement(s)

Stop
PROGRAM CONTROL
 A Simple for example, printing integer 1 to 10.

#include <stdio.h>
void main(void)
{
int nCount;
// display the numbers 1 to 10
for(nCount = 1; nCount <= 10; nCount++)
printf("%d ", nCount);
printf("\n");
}
PROGRAM CONTROL
 Its flow chart…

Start

nCount = 1

nCount++

nCount <=10?
printf("…");

Stop
Examples
Consider a problem of multiplying two
numbers
Algorithm
Step1: Input the numbers as a and b
Step2: find the product a x b
Step3: Print the result
Examples
• To find the highest of three numbers
• Algorithm
• Step 1: read the numbers as x ,y and z
• Step 2: compare x and y
• Step 3: if x > y then compare x with z and find
the greater
• Step 4: Otherwise compare y with z and find
the greater
END

You might also like