Alprog - Elektro KKI
This course introduces the fundamental concepts of algorithms and programming using the C language. Students will learn how to analyze problems, design step-by-step solutions, and implement them in C. The course covers essential programming topics such as variables, data types, operators, control structures (selection and iteration), functions, arrays, pointers, and file handling.
Through lectures, hands-on coding exercises, and projects, students will develop problem-solving skills and a solid foundation in structured programming. By the end of the course, students are expected to be able to write efficient C programs, apply algorithmic thinking to solve computational problems, and understand the importance of programming discipline as a basis for more highly related engineering courses.
Module 1 : Introduction to C
Learning Objectives Understand the fundamental differences between Python and C programming lang...
1. Introduction: From Python to C
1.1 Key Differences Overview Aspect Python C Compilation Interpreted Compiled Type Syste...
2. Input/Output Operations
2.1 Output Operations 2.1.1 Basic Output - printf() Function Signature: int printf(const char *fo...
3. Variables and Data Types
3.1 Variable Declaration Python vs C: Python C x = 5 int x = 5; name = "John" char name[...
4. Arithmetic Operators
4.1 Basic Arithmetic Operators Operator Operation Python Example C Example + Addition a + ...
5. Flow Control
5.1 Conditional Statements 5.1.1 if Statement Python vs C Syntax: Python: if condition: state...
6. More Migration Guide: From Python to C
6.1 Common Syntax Differences Feature Python C Comments # This is a comment // This is a c...
7. Best Basic Practices and Style Guidelines
7.1 Naming Conventions Variables: Use descriptive names (student_count, not sc) Constants: Use u...
8. Practical Examples
8.1 Complete Program Examples Example 1: Simple Calculator #include <stdio.h> int main() { f...
9. Common Debugging Tips
9.1 Compilation Errors Missing semicolons: Add ; at the end of statements Undeclared variables: ...
Module 2 : Functions in C
Learning Objectives: Understand the concept and importance of functions in C programmingDeclare ...
1. Introduction to Functions
1.1 What are Functions? Functions are self-contained blocks of code that perform specific tasks. ...
2. Function Declaration, Definition, and Calling
2.1 Function Anatomy A C function consists of several parts: return_type function_name(parameter_...
3. Parameters and Arguments
3.1 Terminology Parameters (Formal Parameters): Variables in the function definition Arguments (...
4. Return Statement
4.1 Basic Return Usage The return statement serves two purposes: Return control to the calling f...
5. Variable Scope and Lifetime
5.1 Local Variables Variables declared inside a function are local to that function: Scope: Only...
6. Bonus: Some C Library Functions
Throughout this module, we've focused on defining our own functions. However, C also provides a r...
7. Recursion
7.1 Understanding Recursion Recursion is a programming technique where a function calls itself. E...
8. Function Examples and Applications
8.1 Menu-Driven Program #include <stdio.h> // Function prototypes void display_menu(void); int g...
9. Common Errors and Debugging
9.1 Function Declaration Errors Error 1: Missing Function Prototype // ERROR: Function used befor...
Module 3 : Array (Static)
By the end of this module, students will be able to: - Understand the fundamental differences be...
1. Introduction: From Python Lists to C Arrays
1.1 Key Differences Overview Aspect Python Lists C Arrays Size Dynamic (can grow/shrink) F...
2. Array Declaration and Initialization
2.1 Basic Array Declaration Python vs C Comparison: Python C numbers = [1, 2, 3, 4, 5] int...
3. Array Indexing and Access
3.1 Basic Indexing Python vs C Indexing: Operation Python C First element list[0] array[0]...
4. Array Input and Output Operations
4.1 Reading Array Elements 4.1.1 Reading with Known Size #include <stdio.h> int main() { int...
5. Common Array Operations
5.1 Array Traversal 5.1.1 Forward Traversal // Python equivalent: for item in list: for (int i = ...
6. Mathematical Operations on Arrays
6.1 Statistical Operations 6.1.1 Sum and Average #include <stdio.h> int sum_array(int arr[], int...
7. Character Arrays and Strings
7.1 Character Arrays vs Strings Understanding C Strings: In C, strings are arrays of characters t...
8. Multi-dimensional Arrays
8.1 Two-Dimensional Arrays 8.1.1 Declaration and Initialization // Declaration int matrix[3][4]; ...
Module 4 : Pointers & Dynamic Array
By the end of this module, students will be able to: Understand the concept and purpose of point...
1. Introduction to Pointers
1.1 What are Pointers? A pointer is a variable that stores the memory address of another variable...
2. Pointer Basics
2.1 Declaring Pointers Syntax: data_type *pointer_name; Examples: int *ptr; // Pointer to...
3. Pointer Arithmetics
3. Pointer Arithmetic Pointers can be incremented, decremented, and compared. When you perform ar...
4. Pointers and Arrays
Arrays and pointers have a very close relationship in C. In many contexts, an array name acts as ...
5. Pointers and Functions
Pointers are essential for functions to modify variables from the calling code and to work effici...
6. Pointers and Strings
In C, strings are arrays of characters, so pointers work naturally with strings. 6.1 String Repre...
7. Dynamic Memory Allocation & Array
7.1 Introduction to Dynamic Memory Up until now, we've used static memory allocation where array ...
8. Common Pointer Pitfalls and Best Practices
8.1 Uninitialized Pointers WRONG: int *ptr; // Uninitialized - contains garbage address *ptr...
9. Practical Examples with Dynamic Memory
9.1 Dynamic Array with User Input #include <stdio.h> #include <stdlib.h> int main() { int n,...
Module 5 : Data Types (Struct, Enum, TypeDef) & File I/O
By the end of this module, students will be able to: - Understand and implement user-defined dat...
1. Introduction to User-Defined Data Types
1.1 Why User-Defined Types? In previous modules, we learned about basic data types like int, floa...
2. Structures (struct)
2.1 What is a Structure? A structure is a user-defined data type that groups variables of differe...
3. Enumerations (enum)
3.1 What is an Enumeration? An enumeration is a user-defined data type consisting of a set of nam...
4. Type Definitions (typedef)
4.1 What is typedef? typedef creates aliases (alternative names) for existing data types. It make...
5. File Input/Output
5.1 Why File I/O? So far, all our programs lose their data when they terminate. File I/O allows p...