Comprog Reviewer
Comprog Reviewer
C programming is a foundational computer programming language that has had a significant impact on
modern software development.
C was designed for system-level programming and has since become one of the most widely used and
influential programming languages.
computer is an electronic device that processes data according to a set of instructions called a program.
It performs various tasks, such as calculations, data processing, and communication, by executing these
instructions. Computers are capable of storing, retrieving, and manipulating large amounts of data
quickly and accurately, making them essential tools in many aspects of modern life.
Programming is the process of designing, writing, testing, and maintaining the code that instructs a
computer on how to perform specific tasks. This code is written in a programming language, which
consists of a set of rules and syntax that a computer can interpret and execute.
A program is a set of instructions written in a programming language that tells a computer how to
perform a specific task or solve a particular problem. When a program is executed, the computer follows
these instructions step by step to carry out the desired operations
Computer programming is the process of designing and building executable computer software to
accomplish a specific computing task. It involves writing code in a programming language, such as C++,
Python, or Java, to instruct the computer on what actions to perform. The primary activities in computer
programming include:
4. Testing and Debugging: Running the program to find and fix any errors.
5. Documentation: Writing detailed explanations of how the program works and how to use it.
6. Maintenance: Updating the program to fix issues or add new features as needed.
Computer programming is essential in creating applications, systems software, and embedded software
across various industries.
WEEK 2
Late 1960s: The development of the C language began in the late 1960s at Bell Laboratories (AT&T Bell
Labs) in the United States. It was created by Dennis Ritchie as a part of the UNIX operating system
project. The original intention was to develop a language that could be used for system programming on
the PDP-11, a popular minicomputer at the time.
Predecessors:
BCPL (1966): Developed by Martin Richards, BCPL (Basic Combined Programming Language) was a
precursor to C. It was a typeless language designed for writing operating systems and compilers.
B Language (1969): Developed by Ken Thompson, the B language was a simplification of BCPL,
specifically designed for use with the UNIX operating system. However, B was limited in terms of data
types and functionality.
2. Creation of C:
1972: Dennis Ritchie developed C by improving the B language, adding data types and other features to
make it more versatile for system programming. The C language retained the simplicity of B but
introduced key enhancements, such as the concept of data types (e.g., int, char) and a more
comprehensive set of operators.
C Language Features:
Portability: One of C's most significant features was its portability, meaning programs written in C could
be run on different types of machines with minimal modification. This was a major advantage in the era
of diverse computer architectures.
Efficiency: C was designed to provide low-level access to memory and hardware, making it highly
efficient for system-level programming. It allowed direct manipulation of hardware through pointers
and memory addresses.
UNIX and C:
The success of the UNIX operating system played a crucial role in popularizing C. UNIX was almost
entirely written in C, showcasing the language's power and flexibility. As UNIX spread across academic
and commercial institutions, so did the C language.
Standardization:
1978 - "The C Programming Language": Dennis Ritchie and Brian Kernighan published "The C
Programming Language," also known as "K&R C," which became the definitive guide to the language and
a de facto standard.
ANSI C (1989): The American National Standards Institute (ANSI) established a standard for C, known as
ANSI C or C89, to ensure consistency across different implementations of the language.
ISO C (1990): The International Organization for Standardization (ISO) adopted ANSI C, further solidifying
C as a globally recognized programming language standard.
C Today:
Despite being over 50 years old, C remains widely used in system programming, embedded systems, and
high-performance applications. Its simplicity, efficiency, and flexibility continue to make it a popular
choice among programmers and software developers.
WEEK 3
Header Files: C programs often start with #include directives, which include header files containing
definitions and declarations for functions and macros used in the program. Example:
Main Function: Every C program must have a main() function, which serves as the entry point for
execution. Example:
Statements and Expressions: C statements are the instructions executed by the program, ending with a
semicolon (;). Expressions combine variables, operators, and function calls to produce a value.
Syntax Rules:
Case Sensitivity: C is case-sensitive, meaning that Variable and variable are considered different
identifiers.
Braces {}: Used to group statements into blocks, such as in function definitions and control structures.
Comments: Comments are used for documentation within the code. Single-line comments start with //,
and multi-line comments are enclosed between /* and */.
printf is short for print formatted where print refers to output to a printer although the functions are
not limited to printer output.
return 0 means that the program will execute successfully and did what it was intended to do
WEEK 4
Variable Declaration:
Purpose: Declaring a variable means informing the compiler about the variable's name and the type of
data it will store. It reserves memory for that variable based on its data type.
A variable is associated with a specific data type that determines the type of data it can hold
Name (Identifier):
The variable is given a unique name (identifier) that is used to refer to the data stored in that memory
location. The name must follow specific rules (e.g., it cannot start with a number, and it must not be a
reserved keyword in C).
• A variable name can only have alphabets, numbers and the underscore _.
• A variable name cannot be a keyword. For example, int is a keyword that is used to denote
integers.
• A variable name can start with an underscore. However, it's not considered a good practice.
Note: We should try to give meaningful names to variables. For example, first_name is a better variable
name than fn.
Specifiers are keywords used to modify the behavior or characteristics of data types, variables,
functions, or other elements in a program. They provide additional information about how the data
should be interpreted, stored, or accessed. Specifiers play a crucial role in controlling the memory
allocation, size, scope, and functionality of variables and functions.
Format Specifiers:
Used in functions like printf() and scanf() to specify the type of data to be printed or read.
Examples:
%d or %i: Integer
%c: Character
%s: String (array of characters)
%lf: Double
Variable Types
WEEK 5
Operators are fundamental elements in programming languages, including C, that perform operations
on data values. They play a crucial role in developing algorithms, performing calculations, and
controlling the flow of a program. Here's why operators are so important:
o Operators allow for the manipulation and computation of data. Arithmetic operators (+, -, *, /,
%) enable basic mathematical operations necessary for solving equations, performing statistical analysis,
and handling numeric data. For example, they are used to calculate the total price of items, determine
averages, or compute financial projections.
Subtraction (-): Subtracts the second operand from the first (e.g., a - b).
Division (/): Divides the first operand by the second (e.g., a / b).