CAPE_Computer_Science_Unit_1_-_C_Coding_Study_Guide_Crash_Course_1
CAPE_Computer_Science_Unit_1_-_C_Coding_Study_Guide_Crash_Course_1
I don’t like coding myself, so that’s why I put together this, for
Content Breakdown............................................................................................................................................... 5
1. Overview of C Libraries....................................................................................................................................9
Importance and Benefits of Using Libraries......................................................................................................9
Standard C Libraries........................................................................................................................................ 10
Using Library Functions for Common Tasks...................................................................................................11
2. Inputting & Outputting...................................................................................................................................12
Input Functions for Reading Data into Variables.............................................................................................12
Output Functions for Displaying Data on the Screen...................................................................................... 13
Error Handling and Input Validation Techniques............................................................................................ 14
3. Conditional & Iteration Constructs............................................................................................................... 16
Conditional Constructs.....................................................................................................................................16
Iterative Constructs (repetition/looping)..........................................................................................................19
Using Control Structures to Control Program Execution................................................................................ 22
4. Arrays of Type ‘int’ (integer data type)......................................................................................................... 23
Accessing and Manipulating Array Elements..................................................................................................24
Working with Multi-Dimensional Arrays........................................................................................................ 25
Array Traversal and Common Operations....................................................................................................... 27
5. Arrays of Type ‘char’ (character).................................................................................................................. 28
Character Arrays as Strings:............................................................................................................................ 28
String Manipulation Functions:....................................................................................................................... 28
String Input/Output and Formatting:............................................................................................................... 30
Character String Functions.............................................................................................................................. 31
6. Functions...........................................................................................................................................................37
Understanding Functions and their Role in Modular Programming:...............................................................37
Function Declaration, Definition, and Invocation:.......................................................................................... 37
Function Declaration Format:.......................................................................................................................... 38
Passing Arguments to Functions and Returning Values:................................................................................. 39
Recursive Functions and their Applications:................................................................................................... 40
7. Records/Structures (struct).............................................................................................................................41
Introduction to Structures and Their Purpose:................................................................................................. 41
Defining & Declaring Structure Types:........................................................................................................... 41
Accessing Structure Members and Using Dot Notation:.................................................................................42
Working with Arrays of Structures:................................................................................................................. 42
Essential Operations on Structures:................................................................................................................. 43
8. File (Importing & Exporting)......................................................................................................................... 45
File handling operations: opening, closing, reading, and writing files:...........................................................45
Sequential file processing using file pointers:................................................................................................. 45
*Handling text files and binary files (Not Specific to CAPE Syll.):............................................................... 46
Importing data from files and exporting data to files:..................................................................................... 46
Essential operations used for “File Processing”.............................................................................................. 46
Example of a Program that Utilizes both Structures and File Handling Functions in C:................................ 50
9. Testing & Errors.............................................................................................................................................. 54
Syntax Error:....................................................................................................................................................54
1. Range Testing:............................................................................................................................................. 56
2. Desk Checking:............................................................................................................................................56
10. Programming Style & Documentation.........................................................................................................59
Importance of good programming style and readability:.................................................................................59
Proper indentation, spacing, and naming conventions:................................................................................... 59
Use of comments for code documentation:..................................................................................................... 59
Technical and user documentation practices:.................................................................................................. 60
References:............................................................................................................................................................61
MODULE 3: PROGRAMMING
Content Breakdown
1. Libraries In C
● Overview of C libraries.
● Using library functions for common tasks such as input/output, mathematical operations, etc.
● Input functions (scanf, fgets, etc.) for reading data into variables.
● Output functions (printf, puts, etc.) for displaying data on the screen.
● Using control structures to control the flow of program execution based on certain conditions.
6. Functions
7. Records/Structures (struct)
● Example of a Program that Utilizes both Structures and File Handling Functions in C
● Range Testing
● Desk Checking
C libraries are collections of precompiled functions and declarations that provide a wide range of functionality
to C programs. They contain ready-to-use code that can be included in your program to perform specific tasks,
such as input/output operations, mathematical calculations, memory management, string manipulation, and
more. Libraries serve as a foundation for building programs by providing a set of standardized functions and
● Code Reusability (encapsulation): Libraries encapsulate commonly used functionality, allowing you to
reuse existing code rather than rewriting it from scratch. This promotes code modularity and reduces the
● Time and Effort Savings (also encapsulation btw): By utilizing libraries, you can save time and effort
by leveraging preexisting, well-tested functions that are already optimized for specific tasks. This
across different platforms and systems. This allows programs to be easily ported and run on various
● Faster Development (abstraction): Libraries provide high-level abstractions and utility functions that
simplify common programming tasks. By using these functions, you can speed up the development
process and focus on solving the specific problem at hand rather than dealing with low-level details.
Standard C Libraries
C programming language has several standard libraries that are widely used in C programming:
● stdio.h: This library provides functions for input and output operations. It includes functions like printf,
scanf, fgets, fopen, fclose, which allow you to read data from the user, display output, and work with
files.
● stdlib.h: The stdlib.h library offers functions for general-purpose tasks, including memory management,
conversion functions, random number generation, and more. Functions like malloc, free, atoi, rand, exit
● math.h: The math.h library provides mathematical functions for performing various calculations. It
includes functions like sin, cos, sqrt, pow, abs, which enable you to work with trigonometry, logarithms,
● string.h: The string.h library contains functions for manipulating strings, such as copying,
concatenating, comparing, and searching. Functions like strcpy, strcat, strlen, strcmp are part of this
library.
These are just a few examples of standard C libraries. Depending on the specific requirements of your program,
you may also need to include other libraries that provide additional functionality, such as networking, graphics,
databases, etc.
To use functions from C libraries, you need to include the corresponding library header file using the #include
directive at the beginning of your program. This allows your program to access the function declarations and
program:
#include <stdio.h>
Once you've included the library, you can call the functions provided by that library in your code. For instance,
you can use the printf function from stdio.h to display output to the console:
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
Here, the printf function from the stdio.h library is used to display the "Hello, world!" message on the screen.
2. Inputting & Outputting
In C programming, input functions are used to read data from the user or external sources and store it in
● scanf(): The scanf() function allows you to read formatted input from the user or from a file. It takes a
format string as a parameter, which specifies the expected data format, and assigns the input values to
the specified variables. When using scanf(), you need to use the ampersand sign (&) before the variable
names of integers, real numbers, and characters to indicate the memory address where the input should
int age;
This code reads an integer value from the user and stores it in the variable 'age'.
● fgets(): The fgets() function is used to read a line of text from a file or from the user. It takes the
destination buffer and the maximum number of characters to read as parameters. For example:
char name[50];
Output functions in C are used to display data on the screen or write it to a file. The two commonly used output
functions are:
● printf(): The printf() function is used to display formatted output on the screen. It takes a format string
as a parameter, which specifies the desired output format, and additional arguments containing the
This code displays the value of the variable 'num' as part of the output message.
● puts(): The puts() function is used to display a string of characters on the screen. It takes a string as a
parameter and automatically appends a newline character at the end. For example:
puts(message);
- scanf("%d",&integer_variable);
- scanf("%f",&float_variable);
- scanf("%s",&string_variable);
- scanf("%c",&char_variable);
- scanf("%p",&point_variable);
Error handling and input validation are important aspects of input/output operations. Here are some techniques
● Checking Return Values: Most input functions return a value (return 0;) indicating the success
or failure of the operation. It is important to check these return values to detect errors and handle them
appropriately.
● Input Validation Loops: Use loops to repeatedly prompt the user for input until valid data is entered.
This helps to ensure that the program does not proceed with incorrect or unexpected input.
statements, to validate input based on specific conditions. You can check input ranges, data types, or
● *Buffer Management (not specific to CAPE Syll.): When using functions like fgets(), be cautious
about buffer overflow. Ensure that the input does not exceed the size of the destination buffer to prevent
memory-related errors.
3. Conditional & Iteration Constructs
Conditional Constructs
Conditional constructs allow you to control the flow of program execution based on certain conditions. In C, the
● IF Control Structure: The IF control structure allows you to execute a block of code if a specified
if (condition) {
if (num > 0) {
● IF-ELSE Control Structure: The if-else control structure allows you to execute one block of code if a
condition is true and another block of code if the condition is false. It has the following syntax:
if (condition) {
} else {
● Case Control Structure: The case control structure, also known as the switch statement, allows you
to select one of many code blocks to be executed based on the value of a variable or an expression (Like
switch (expression) {
case value1:
break;
case value2:
break;
// ...
default:
value}
Example of the Case Control Structure:
int day = 3;
switch (day) {
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
default:
printf("Invalid day\n");
}
Iterative Constructs (repetition/looping)
Iterative constructs allow you to repeat a block of code multiple times until a specified condition is met. In C,
● For Loop: The for loop is used when you know the number of iterations in advance. It has the
following syntax:
printf("%d\n", i);
In this code, the loop variable i is initialized to 1, and the loop executes as long as the condition i <= 5 is true.
● While Loop:
- The while loop is used when you want to repeat a block of code based on a condition.
- If the precise moment at which the condition will be met is known, it is called a bounded loop;
while (condition) {
int counter = 0;
counter++;
In this example, the while loop will execute as long as the counter variable is less than 5. Once the counter
char input;
while (1) {
if (input == 'q') {
In this example, the while loop continues indefinitely until the user enters the character 'q'. Once 'q' is entered,
N.B: An unbounded while loop must have a proper termination condition within the loop body to prevent it
● Do-While Loop: The do-while loop is similar to the while loop but guarantees that the block of code is
executed at least once before checking the condition. It has the following syntax:
do {
} while (condition);
Example of the Do While Loop Construct:
int i = 1;
do {
printf("%d\n", i);
i++;
In this code, the loop executes the code block at least once and then checks the condition i <= 5. If the
Conditional and iteration constructs provide you with control structures that enable you to control the flow of
By using if statements, switch statements, for loops, while loops, and do-while loops, you can make decisions,
These control structures allow you to handle different scenarios, execute specific code blocks based on
conditions, and create loops to iterate over data or perform repetitive tasks. They give you the flexibility to
An array is a collection of elements of the same data type. In C, arrays are zero-indexed, meaning the first
element is positioned at index 0. Here's an example showing the positioning of the first array at 0, the second
Position (index) 0 1 2 3 4
Member 10 20 30 40 50
Array elements can be accessed and manipulated using their indices. Here's an example:
A multi-dimensional array is an array with more than one dimension. It is like having arrays within arrays.
For example, a two-dimensional array, also known as a matrix, can be declared and initialized as follows:
and 3 columns
In the table below, the 2D integer array named matrix from above is shown. Each member of the array is
identified by its position (index), denoted as [row][column], and listed in the "Member" column.
Position [0,0] [0,1] [0,2] [1,1] [1,2] [1,3] [2,1] [2,2] [2,3]
(index)
Member 1 2 3 4 5 6 7 8 9
To access elements in a multi-dimensional array, multiple indices must be used.For example:
2 (6)
Working with multi-dimensional arrays allows the organization and manipulation of data in a tabular or
grid-like structure. By understanding the indexing scheme and accessing elements using multiple indices, you
Array traversal involves accessing and processing each element in an array. Common operations on arrays
include finding the minimum or maximum element, calculating the sum or average, searching for a specific
value, and sorting. Here's an example of finding the maximum element in an array:
is found
This example demonstrates how to traverse the array numbers and find the maximum element.
5. Arrays of Type ‘char’ (character)
In C, character arrays are often used to represent strings. A string is a sequence of characters terminated by a
null character ('\0'). By understanding how to work with character arrays as strings, utilize string manipulation
functions, and perform string input/output and formatting, you'll have the necessary skills to handle text-based
data efficiently.
Character arrays can be used to store and manipulate strings in C. Here's an example of declaring and
In the example above, myString is a character array that can hold up to 10 characters, including the null
character. It is initialized with the string "Hello". Keep in mind that the size of the array should be large enough
C provides several string manipulation functions that allow you to perform various operations on strings. Some
These functions are part of the string.h library. Here's an example that demonstrates the use of strlen() and
strcpy():
#include <stdio.h>
#include <string.h>
int main() {
char destination[20];
strcpy(destination, source);
return 0;
In the example above, strlen() calculates the length of the source string, and strcpy() copies the source string to
C provides input/output functions specifically designed for strings. For input, scanf() can be used with the %s
format specifier to read a string from the user. For output, printf() can be used with the %s format specifier to
display a string.
Here's an example:
#include <stdio.h>
int main() {
char name[20];
scanf("%s", name);
return 0;
In the example above, scanf("%s", name) reads a string from the user and stores it in the name array. The
printf() statement then displays a greeting message using the entered name.
Additionally, C provides various formatting options to control how strings are displayed. For example, you can
use the %10s format specifier to specify a minimum field width of 10 characters when printing a string.
In C, character arrays are often used to represent strings. Understanding how to declare, assign values to, output,
manipulate, and perform various operations on character arrays will allow you to effectively work with strings
in your programs.
char myString[SIZE];
Example:
char name[20];
This code declares a character array named name with a size of 20, capable of holding a string of characters.
myString[index] = value;
Example:
name[0] = 'J';
This code assigns the character 'J' to the first element of the name array.
strcpy(myString, "value");
Example:
strcpy(name, "John");
This code assigns the string "John" to the name array using the strcpy function.
Example:
This code outputs the value of the name array, which represents a string.
printf("%c", myString[index]);
Example:
char myArray[NUM_STRINGS][SIZE];
Example:
char fruits[3][10];
This code creates a 2-dimensional character array named fruits, capable of holding 3 strings with a maximum
scanf("%s", myArray[index]);
Example:
scanf("%s", fruits[0]);
This code reads a string from the user and stores it in the first element of the fruits array.
strlen(myString);
Example:
This code calculates and stores the length of the name string in the variable length using the strlen function.
9. To Compare Two (2) String Variables to Determine if they are the same:
//printf statement;
Example:
if (strcmp(name1, name2) == 0) {
This code compares the strings name1 and name2 using the strcmp function and if construct. If the return value
strcat(destination, source);
Example:
strcat(greeting, name);
This code concatenates the string in the name array to the end of the string in the greeting array using the
strcat function.
11. To Copy the Content of One (1) String Variable to Another String Variable:
strcpy(destination, source);
Example:
char destination[10];
strcpy(destination, source);
This code copies the content of the source array to the destination array using the strcpy function.
The Following Program Code Shows how a String Variable is Traversed, so as to Determine if any of the
#include <stdio.h>
#include <string.h>
int main() {
char word[20];
scanf("%s", word);
int i;
return 0
This program prompts the user to enter a word, and then it traverses the characters of the word to determine if
Functions are an essential concept in modular programming. They allow you to break down a program into
smaller, manageable, and reusable pieces of code. Functions encapsulate a set of instructions and can be called
from different parts of a program whenever needed. This modular approach promotes code reusability,
● Function Declaration: A function declaration informs the compiler about the existence of a function,
its name, return type, and the types of parameters it accepts. It serves as a prototype for the function.
Example:
● Function Definition: The function definition contains the actual implementation of the function. It
specifies the return type, function name, and the body of the function that contains a set of
instructions.
Example:
int sum = a + b;
return sum;
}
● Function Invocation: To use a function, you invoke/call it by its name, passing the required arguments
(if any). The function executes its code and may return a value.
Example:
● return_type: Specifies the data type of the value the function returns. It can be void if the function does
● function_name: Represents the name of the function, which should be unique within the program.
● (datatype parameter_name): Specifies the data type and name of the parameters the function accepts.
Including these elements in a function declaration is crucial as it provides essential information to the compiler
and other developers working with the code. It clarifies the expected return type, function name, and the types
Passing Arguments: Functions can accept parameters/arguments, which are values passed to the function when
it is called. Arguments provide input data for the function to work with.
Example:
The function greetUser takes a character array name as an argument and prints a personalized greeting
message.
● Returning Values: Functions can also return a value to the calling code. The return type specified in
the function declaration indicates the type of the value the function will return. Use the return statement
Example:
return result;
The function square takes an integer num as an argument, calculates its square, and returns the result.
Recursive Functions and their Applications:
A recursive function is a function that calls itself from within its own body. It enables solving complex
problems by breaking them down into smaller, similar sub-problems. Recursive functions have two
Example:
int factorial(int n) {
if (n == 0) {
} else {
The function factorial calculates the factorial of a given number n using recursion. The base case is when n is
0, returning 1. In the recursive case, the function calls itself with n-1 and multiplies the result by n.
Recursive functions are commonly used in algorithms such as tree traversal, sorting (e.g., quicksort), and
Functions play a vital role in structuring programs, promoting code reuse, and managing complexity. They
allow you to break down problems into smaller tasks and encapsulate logic within self-contained units of code,
making your programs more modular and easier to understand and maintain.
7. Records/Structures (struct)
Structures, also known as records, are user-defined data types in C that allow you to combine different types of
variables under a single name. They provide a way to represent a collection of related data items as a single
unit. Structures are useful when you need to organize and manipulate data that has different properties but
Declaring a Structure Type: To declare a structure type, you use the struct keyword followed by the structure
name. Inside the structure, you define the members (variables) that make up the structure.
● Example:
struct Person {
char name[50];
int age;
float salary;
};
Defining Structure Variables: After declaring a structure type, you can define variables of that type by
Example:
Structure members are accessed using the dot notation (.), which allows you to access individual members of
a structure variable.
Example:
employee1.age = 30;
employee1.salary = 5000.0;
You can create arrays of structures to store multiple records of the same structure type. This allows you to
Example:
1. To Declare a New Instance of Type "record_name": To declare a new instance of a structure type, use
Example:
This code declares a new instance of the Person structure named employee3. It creates a variable of type
Person that can hold data for an individual person, such as their name, age, and salary.
2. To Assign Values to Data Fields in a Record in C: Use the dot notation to assign values to the data
Example:
employee2.age = 25;
This code assigns the value 25 to the age field of the employee2 structure.
3. To Declare an Array of a particular Record in C: Use the structure name followed by the array
Example:
This code declares an array employees of type Person with a size of 5. It creates an array that can store
information for multiple employees, with each element of the array being a Person structure.
4. To Assign Values to Data Fields in an Array of Records in C: Use the dot notation and array
indexing to assign values to the data fields of individual structures within the array.
Example:
employees[0].salary = 6000.0;
This code assigns the value 6000.0 to the salary field of the first structure in the employees array.
5. To Assign All the Values of one (1) Instance of a Record to another Instance: Use the assignment
Example:
employee2 = employee1;
This code assigns all the values of the employee1 structure to the employee2 structure.
6. To Pass a Record to a Function: Declare a function parameter with the structure type, and pass the
Example:
This code defines a function displayEmployee that takes a Person structure as a parameter and displays its
contents.
8. File (Importing & Exporting)
● Opening a file: In C, you can use the fopen() function to open a file. It takes two parameters: the file
name and the mode (e.g., "r" for reading, "w" for writing, "a" for appending). The function returns a file
● Closing a file: To close a file, you can use the fclose() function and pass it the file pointer. This step is
essential to release system resources and ensure that all data is properly written to the file.
● Reading from a file: To read data from a file, you can use functions such as fscanf() or fgets(). These
functions allow you to read data from the file and store it in variables or character arrays.
● Writing to a file: To write data to a file, you can use functions such as fprintf() or fputs(). These
● File pointers: In C, a file pointer is a special variable that points to a specific location in a file. It
keeps track of the current position for reading or writing data. You can declare a file pointer
● Sequential file processing: Sequential file processing involves reading or writing data in a
sequential manner from the beginning of the file to the end, or vice versa. You can use loops and
● Text files: Text files store data in plain text format, where each character is represented by its
corresponding ASCII value. Text files are human-readable and can be edited with a text editor.
● Binary files: Binary files store data in a binary format, which means that the data is represented
in its raw binary form. Binary files are not human-readable and often contain complex data
● Importing data from files: You can import data from files by opening the file in read mode and
using appropriate file reading functions. The data can be read and stored in variables or data
● Exporting data to files: You can export data to files by opening the file in write mode or append
mode and using appropriate file writing functions. The data can be formatted and written to the
1. To Declare a File in C:
Example:
FILE *filePointer;
In C, you can declare a file using the FILE data type and a file pointer. The file pointer will be used to access
● Example:
FILE *filePointer;
To open a file in "read-only" mode, you can use the fopen() function with the file name and the mode "r". This
● Example:
FILE *filePointer;
To open a file in "write-only" mode, you can use the fopen() function with the file name and the mode "w". This
allows you to write data to the file. If the file already exists, its previous content will be overwritten.
4. To Write to a File:
● Example:
FILE *filePointer;
filePointer = fopen("filename.txt", "w");
After opening a file in "write-only" mode, you can use the fprintf() function to write data to the file. The data is
● Example code:
FILE *filePointer;
char buffer[100];
After opening a file in "read-only" mode, you can use the fgets() function to read data from the file. The data is
read into a character array (buffer in this example) using the file pointer.
6. To Close a File:
● Example:
FILE *filePointer;
fclose(filePointer);
To close a file, you can use the fclose() function and pass it the file pointer. This step is important to release
● Example:
FILE *filePointer;
if (filePointer == NULL) {
exit(0);
If the file pointer is NULL after attempting to open the file. If the file pointer is NULL, it means the file does
not exist or could not be opened for some reason. In such cases, we display an appropriate message to the user
● Example:
FILE *filePointer;
int data;
When reading data from a file, you can use the fscanf() function inside a loop. The function returns the number
of successful conversions, and when it reaches the end of the file, it returns EOF (End-Of-File) which can be
Example of a Program that Utilizes both Structures and File Handling Functions in C:
The program on the following page, allows the user to enter the names, ages, and averages of five (5) students.
The information is then stored in a file called "students.txt" using the fprintf() function. Later, the program
reads the data from the file using fscanf() and displays it to the user using printf(), A FULL Explanation of
EACH element in the code will be ont the following page, after the code:
#include <stdio.h>
struct Student {
char name[50];
int age;
float average;
};
int main() {
FILE *filePointer;
write mode
if (filePointer == NULL) {
return 1;
&student.average);
read mode
if (filePointer == NULL) {
return 1;
printf("\nStudent Information:\n");
the file
}
fclose(filePointer); // Close the file
return 0;
Explanation:
● The filePointer is a pointer to a FILE object, which will be used to handle the file.
● The code opens the file "students.txt" in write mode using fopen() and checks if the file was
successfully opened. If not, it displays an error message and returns 1 to indicate an error.
● The program then prompts the user to enter the name, age, and average for five students using a loop.
The data entered by the user is written to the file using fprintf().
● The code opens the file "students.txt" again, but this time in read mode.
● It then reads the student information from the file using fscanf() in a loop until the end of the file
(EOF) is reached. The data is read into the student structure and displayed on the console.
Syntax Error:
1. A syntax error occurs when the code violates the rules of the programming language, resulting in a
compilation error.
#include <stdio.h>
int main() {
statement
return 0;
In this example, the missing semicolon at the end of the printf statement is a syntax error. The code will not
2. A semantic error occurs when the code is grammatically correct but produces unintended or incorrect
results.
#include <stdio.h>
int main() {
int a = 5;
int b = 0;
int result;
return 0;
In this example, the division by zero is a semantic error. The code will compile and run without any syntax
errors, but it will produce an error at runtime due to the attempted division by zero.
Semantic errors can also occur when the logic of the code is incorrect, leading to unintended behavior or
incorrect results. These errors often require thorough testing and debugging to identify and resolve.
1. Range Testing:
● Range testing involves validating input data to ensure it falls within the expected range. It helps
● For example, if a function expects an integer input between 1 and 10, range testing involves
checking if the provided value is within that range before performing any further operations.
2. Desk Checking:
● Desk checking is a manual method of testing code by mentally executing the code on paper or
● It involves analyzing the code line by line, tracking variable values, and evaluating the expected
● By carefully examining the code and its execution, desk checking helps identify logic errors,
#include <stdio.h>
int main() {
int a = 5;
int b = 3;
int result;
result = a + b;
return 0;
}
Desk Checking:
1. Assign a a value of 5.
2. Assign b a value of 3.
3. Declare result.
By going through this process of desk checking, you can verify the correctness of the code manually before
running it. It allows you to catch potential errors, trace the flow of execution, and ensure the expected results are
produced.
10. Programming Style & Documentation
1. Good programming style and readability are essential for creating maintainable, understandable, and
bug-free code. A well-written code is easier to comprehend, debug, and modify. It enhances
collaboration among developers and improves the overall quality of the software. By following good
programming style practices, you ensure that your code is clean, consistent, and easy to follow.
2. Indentation and spacing are used to visually structure the code and make it more readable. Consistent
indentation, such as using spaces or tabs, helps in visually identifying code blocks and nested structures.
Proper spacing around operators, commas, and parentheses improves code clarity.
Naming conventions play a vital role in code readability. Choosing meaningful and descriptive names
for variables, functions, and other identifiers makes the code self-explanatory. It is recommended to use
camel case (e.g., myVariable) or underscores (e.g., my_variable) for naming variables and functions.
3. Comments are used to provide explanations, clarifications, and documentation within the code. They
help other developers (including yourself in the future) understand the purpose, logic, and usage of
various parts of the code. Comments should be used to describe complex algorithms, summarize code
sections, and highlight important details. It is essential to maintain comments and update them as the
code evolves.
Technical and user documentation practices:
4. Technical documentation focuses on explaining the inner workings of the code, such as APIs, libraries,
and modules. It includes information about functions, data structures, input/output formats, and error
handling. Technical documentation is often created using tools like Javadoc, Doxygen, or Markdown,
and it helps other developers understand how to use and contribute to the codebase.
User documentation aims to provide instructions and guidance for end-users of the software. It includes
user manuals, installation guides, FAQs, and tutorials. User documentation should be written in a clear
West, J. O. (2013). Computer Science for CAPE® Examinations UNIT 1. Caribbean Educational Publishers.