This document discusses different types of errors that can occur in programming:
1) Compilation errors occur when the compiler cannot compile source code due to issues like typos.
2) Linker errors are rare and usually due to misspelling library function names.
3) Execution errors happen at runtime from issues like division by zero.
4) Logical errors are mistakes in program logic not caught by the compiler that result in unexpected output.
2. Compilation errors
• Error occurs when the compiler finds something in the source
code that it can’t compile.
• A misspelling, typographical error, or any of a dozen other
things can cause the compiler to choke.
• Hello.c:Error:’;’ expected
3. Linker error messages
• Relatively rare and usually result from misspelling the name of
a C library function.
• Error: undefined symbols: error message, followed by the
misspelled name (preceded by an underscore).
• Once you correct the spelling, the problem should go away.
4. Execution error
Errors occur during the program execution, after a successful
compilation.
Common execution errors are a numerical overflow or
underflow (exceeding the largest or smallest permissible
number that can be stored in the computer), division by zero,
attempting to compute the logarithm or the square root of a
negative number, etc.
These diagnostics are sometimes called execution messages
or run-time messages.
5. Logical Error
• Error done by programmer by giving different logical mistakes.
Logical error is not detected by the compiler.
• Syntax will be correct but the output of the program will be
different than that of expected output.
6. ASSEMBLERS, COMPILERS AND INTERPRETERS
The assemblers, compilers, or interpreters are the software
that converts HLL to LLL.
ASSEMBLER
Language which substitutes letters and symbols for the
numbers in the machine language program is called an
assembly language or symbolic language.
Program written in symbolic language that uses symbols
instead of numbers is called an assembly code or a symbolic
program.
Translator program that translates an assembly code into the
computer’s machine code is called an assembler.
7. ASSEMBLER
Assembler is a system program which is supplied by the
computer manufacturer.
Because in addition to translating the assembly code to
machine code, it also assembles the machine code in the
main memory of the computer and makes it ready for
execution.
Symbolic program written by program in assembly language is
called a source program.
After the source program has been converted into machine
language by an assembler, it is referred to as an object
program.
8. Assembler translates each assembly language instructions into an
equivalent machine language instruction, there is a one-to-one
correspondence between the assembly instructions of the source
program and the machine instructions of object program.
COMPILER
Translating program that translates the instruction of a high level
language into machine language.
Compiler translated the whole program at once and this process is
called compilation.
Compiler can translate only those source programs which have
been written in the language for which the computer is meant.
9. Compilers are large programs which reside permanently on
secondary storage.
When the translation of a program is to be done, they are
copied into the main memory of the computer.
Compiler analyses each statement in the source program and
generates a sequence of machine instructions, when
executed, will precisely carry out the computation specified in
the statement.
As the compiler analyses each statement, it may detects
certain types of errors, which are called compile time errors.
10. A source program containing an error diagnosed by the
compiler will not be compiled into an object program.
Compiler will print out a suitable message along with a list of
coded error messages which indicate the type of errors.
Compiler, however, can not diagnose logical errors. It can only
diagnose syntax errors in a program.
11. INTERPRETER
An interpreter is another type of translator used for
translating high level languages into machine code.
Takes the statement of a high level language and translates it
into a machine instruction which is immediately executed.
During programming, programmer can not proceed to next
line till the current line is error free.
Advantage of an interpreter over a compiler is fast response
to changes in the source program.
It is a time consuming translation method because each
statement must be translated every time it is executed from
the source program.
12. Compiled machine language program runs much faster than
an interpreted program.
13. ALGORITHMS
Algorithm is a verbal or says written form of the program. It can
also be defined as ordered description of instructions to be carried
out in order to solve the given task.
For example:
• Program: preparing tea
• Start
• Fetch water and tea leaves along with sugar and milk
• Boil the water
• Put tea leaves and sugar in boiled water
• Mix with milk
• Server the tea
• Stop
14. Basic guidelines for writing Algorithms
Use plain language.
Do not use any language specific syntax. Same algorithm
should hold true for any programming language.
Do not make any assumptions. Describe everything clearly
and explicitly.
Ensure that the algorithm has single entry and exit point.
15. Important features of Algorithm
1. Finiteness: Every algorithm should lead to a session of
task that terminates after a finite number of steps.
2. Definiteness: Each step must be precisely defined. Actions
should be unambiguously specified for each case.
3. Inputs: Any algorithm can have zero or more inputs. Inputs
may be given initially or as the algorithm runs.
4. Outputs: Any algorithm may result in one or more outputs.
Quantities that have specified relation to inputs.
5. Effectiveness: All operations must be sufficiently basic so
as to be implemented with even paper and pencil.
16. For example: A procedure to pick the largest tender from a set of tenders
Step 1: Read the first tender and note down its value as the maximum
tender value so far encountered. Note down the tender
identification number.
Step 2: As long as tenders are not exhausted do steps 3 and 4. go to
step 5 when tenders are exhausted.
Step 3: Read the next tender and compare the tender with the current
maximum tender value.
Step 4: If this tender value is greater than that previously noted down
as maximum tender then erase the previous maximum value noted
and replace it by this new value. Replace the previously noted
tender identification number of this identification number. Else do
not do anything.
Step 5: Print the final value of maximum tender and its identification
noted down in step 4.
17. FLOWCHART
Diagrammatic representation of algorithm.
Flowchart represents the actual flow of program during
program execution.
It is very helpful for debugging or tracing the flow of the
program.
Flowchart is drawn using basic blocks, each having special
meaning.
Basic blocks used for drawing flowcharts.