CE4703 Study Guide Lewis Ubebe
C Language Notes
Table of Contents
C Language Notes.................................................................................................................................................... 1
Unit 1: Introduction to the C Language...................................................................................................... 2
Basic Language Rules................................................................................................................................... 2
Compiling and Running a C Program..................................................................................................... 2
Console Input/Output.................................................................................................................................. 3
Operators, Expressions, and Statements.............................................................................................. 3
Structured Program Development in C................................................................................................. 3
Functions – The Units of a C Program.................................................................................................... 3
Introduction to Arrays................................................................................................................................. 4
Unit 2: Software Development Practices & Tools.................................................................................. 4
Using Doxygen................................................................................................................................................. 4
Tag Descriptions............................................................................................................................................. 5
Summary of the 7 Steps in Program Construction:........................................................................10
Modular Programming.............................................................................................................................. 10
Unit 3: User-Defined Data Types and Dynamic Data Structures...................................................10
User-Defined Data Types.......................................................................................................................... 10
Unit 4: Algorithms............................................................................................................................................ 21
What are Algorithms?................................................................................................................................ 21
Algorithmic Structures.............................................................................................................................. 21
Algorithm Performance Analysis.......................................................................................................... 22
Sorting Algorithms...................................................................................................................................... 23
Searching Algorithms................................................................................................................................. 26
1
, CE4703 Study Guide Lewis Ubebe
Unit 1: Introduction to the C Language
Basic Language Rules
Identifiers:
Names for variables, functions, and other user-defined entities. Must begin with a letter or
underscore, followed by letters, digits, or underscores. Case-sensitive.
Variables:
Storage for data with a specific type. Declared with a type and a name (e.g., int x;).
Constants:
Fixed values that do not change. Defined using #define or const (e.g., const float PI = 3.14;).
Compiling and Running a C Program
The process of turning your C program into an executable happens in four stages:
1.1. Preprocessing
What happens: The preprocessor looks for special commands in your code that
start with #, like #include and #define.
o It includes content from external files (like stdio.h for input/output).
o It replaces macros (like #define MAX 100) with their values.
o It removes comments from the code.
Result: The code is ready for the next stage, with all these changes applied.
1.2. Compilation
What happens: The compiler takes the preprocessed code and translates it into a
lower-level form called assembly language.
o This is the first step where the code is converted into a form that the
computer can understand more directly.
Result: Assembly language code, specific to the type of computer you are using.
1.3. Assembly
What happens: The assembler converts the assembly code into machine code,
which is a binary form that the computer's processor can execute.
o It creates an object file (usually with .o or .obj extension) which contains the
binary code.
Result: An object file with machine code that isn't yet a complete program.
2
, CE4703 Study Guide Lewis Ubebe
1.4. Linking
What happens: The linker takes the object file(s) and combines them with any
necessary libraries (like the standard library) to create the final program.
o It connects functions and variables used in your code to their correct
locations in memory.
Result: A complete executable program that can run on your computer.
Console Input/Output
- Input: scanf() function to read data.
- Output: printf() function to display data.
Operators, Expressions, and Statements
- Operators: Arithmetic (+, -, *, /), Relational (<, >, ==), Logical (&&, ||), Bitwise (&, |, ^).
- Expressions: Combinations of operators and operands.
- Statements: Executable instructions (e.g., assignment, loops, conditionals).
Structured Program Development in C
- Steps:
1. Define the problem.
2. Plan using flowcharts or pseudocode.
3. Write and debug the code.
4. Test the program.
Functions – The Units of a C Program
- Creating and Calling Functions:
3
C Language Notes
Table of Contents
C Language Notes.................................................................................................................................................... 1
Unit 1: Introduction to the C Language...................................................................................................... 2
Basic Language Rules................................................................................................................................... 2
Compiling and Running a C Program..................................................................................................... 2
Console Input/Output.................................................................................................................................. 3
Operators, Expressions, and Statements.............................................................................................. 3
Structured Program Development in C................................................................................................. 3
Functions – The Units of a C Program.................................................................................................... 3
Introduction to Arrays................................................................................................................................. 4
Unit 2: Software Development Practices & Tools.................................................................................. 4
Using Doxygen................................................................................................................................................. 4
Tag Descriptions............................................................................................................................................. 5
Summary of the 7 Steps in Program Construction:........................................................................10
Modular Programming.............................................................................................................................. 10
Unit 3: User-Defined Data Types and Dynamic Data Structures...................................................10
User-Defined Data Types.......................................................................................................................... 10
Unit 4: Algorithms............................................................................................................................................ 21
What are Algorithms?................................................................................................................................ 21
Algorithmic Structures.............................................................................................................................. 21
Algorithm Performance Analysis.......................................................................................................... 22
Sorting Algorithms...................................................................................................................................... 23
Searching Algorithms................................................................................................................................. 26
1
, CE4703 Study Guide Lewis Ubebe
Unit 1: Introduction to the C Language
Basic Language Rules
Identifiers:
Names for variables, functions, and other user-defined entities. Must begin with a letter or
underscore, followed by letters, digits, or underscores. Case-sensitive.
Variables:
Storage for data with a specific type. Declared with a type and a name (e.g., int x;).
Constants:
Fixed values that do not change. Defined using #define or const (e.g., const float PI = 3.14;).
Compiling and Running a C Program
The process of turning your C program into an executable happens in four stages:
1.1. Preprocessing
What happens: The preprocessor looks for special commands in your code that
start with #, like #include and #define.
o It includes content from external files (like stdio.h for input/output).
o It replaces macros (like #define MAX 100) with their values.
o It removes comments from the code.
Result: The code is ready for the next stage, with all these changes applied.
1.2. Compilation
What happens: The compiler takes the preprocessed code and translates it into a
lower-level form called assembly language.
o This is the first step where the code is converted into a form that the
computer can understand more directly.
Result: Assembly language code, specific to the type of computer you are using.
1.3. Assembly
What happens: The assembler converts the assembly code into machine code,
which is a binary form that the computer's processor can execute.
o It creates an object file (usually with .o or .obj extension) which contains the
binary code.
Result: An object file with machine code that isn't yet a complete program.
2
, CE4703 Study Guide Lewis Ubebe
1.4. Linking
What happens: The linker takes the object file(s) and combines them with any
necessary libraries (like the standard library) to create the final program.
o It connects functions and variables used in your code to their correct
locations in memory.
Result: A complete executable program that can run on your computer.
Console Input/Output
- Input: scanf() function to read data.
- Output: printf() function to display data.
Operators, Expressions, and Statements
- Operators: Arithmetic (+, -, *, /), Relational (<, >, ==), Logical (&&, ||), Bitwise (&, |, ^).
- Expressions: Combinations of operators and operands.
- Statements: Executable instructions (e.g., assignment, loops, conditionals).
Structured Program Development in C
- Steps:
1. Define the problem.
2. Plan using flowcharts or pseudocode.
3. Write and debug the code.
4. Test the program.
Functions – The Units of a C Program
- Creating and Calling Functions:
3