7.ICP - Preventing or fixing errors in structured programs.
7.ICP - Preventing or fixing errors in structured programs.
programs
To prevent or resolve errors in structured programs,
programmers should consider using variable identifiers with
meaningful and consistent names, adding comments to explain
the code, following a clear flow of execution, and utilising
debugging techniques such as incremental program
development and backtracking. Moreover, by designing the
overall logic and structure of the program using tools like
flowcharts and pseudocode, programmers can minimise errors
and reduce debugging time. Additionally, handling exceptions
and using error codes can help prevent runtime errors.
1
-Common conventions within programs can help provide extra
information about the function or role of specific variables,
making it easier to understand and troubleshoot code.
2
Tracing the flow of execution:
-Understanding the flow of program execution is essential for
pinpointing errors and optimising code performance. By
employing techniques to trace the program's execution path,
programmers can identify potential issues, analyse program
behaviour, and enhance overall code efficiency.
-Identifying the stages of flow execution helps in understanding
how the program functions and where errors may occur.
-Using appropriate techniques to trace the flow of execution,
such as manually tracing the code, using debuggers, or
analysing output information.
-Keeping track of the trace can be done by using markers,
debuggers, or other methods to track the execution path of the
program.
3
6.Document findings, actions, and outcomes.
Uninitialised variables Int num1, num2; //not assigning values to num1 and num2 before using them.
Off-by-one errors for(int i =0; i<=5; i++)//this loop was intended to be i<5
Ambiguities Int x =5; int y = 10; int result = x + y *2; //unclear operator precedence.
Semantic errors int total = num1 * num2; //semantically incorrect operation for the context.