Advanced Search
Search Results
65 total results found
1. Introduction: From Python to C
1.1 Key Differences Overview Aspect Python C Compilation Interpreted Compiled Type System Dynamic typing Static typing Memory Management Automatic Manual Syntax Style Indentation-based Brace-based Performance Slower execution Faster execution ...
2. Input/Output Operations
2.1 Output Operations 2.1.1 Basic Output - printf() Function Signature: int printf(const char *format, ...); Python vs C Comparison: Python C print("Hello") printf("Hello\n"); print("Value:", x) printf("Value: %d\n", x); print(f"x = {x}") printf("x...
3. Variables and Data Types
3.1 Variable Declaration Python vs C: Python C x = 5 int x = 5; name = "John" char name[] = "John"; pi = 3.14 float pi = 3.14f; 3.2 Basic Data Types 3.2.1 Integer Types Type Size (bytes) Range Usage char 1 -128 to 127 Small integers, chara...
4. Arithmetic Operators
4.1 Basic Arithmetic Operators Operator Operation Python Example C Example + Addition a + b a + b - Subtraction a - b a - b * Multiplication a * b a * b / Division a / b a / b % Modulus a % b a % b 4.2 Important Division Differences Integer D...
5. Flow Control
5.1 Conditional Statements 5.1.1 if Statement Python vs C Syntax: Python: if condition: statement1 statement2 elif another_condition: statement3 else: statement4 C: if (condition) { statement1; statement2; } else if (another_condition)...
6. More Migration Guide: From Python to C
6.1 Common Syntax Differences Feature Python C Comments # This is a comment // This is a comment Block Comments """Multi-line""" /* Multi-line */ Code Blocks Indentation { } braces Statement End Line break ; semicolon Boolean Values True, False ...
7. Best Basic Practices and Style Guidelines
7.1 Naming Conventions Variables: Use descriptive names (student_count, not sc) Constants: Use uppercase (MAX_SIZE, PI) Functions (we will learn more about this in the next module): Use verb-noun pattern (calculate_area, print_result) 7.2 Code Organization #...
8. Practical Examples
8.1 Complete Program Examples Example 1: Simple Calculator #include <stdio.h> int main() { float num1, num2, result; char operator; printf("Enter first number: "); scanf("%f", &num1); printf("Enter operator (+, -, *, /): "); ...
9. Common Debugging Tips
9.1 Compilation Errors Missing semicolons: Add ; at the end of statements Undeclared variables: Declare variables before using them Type mismatches: Ensure compatible types in assignments (this mostly happens in function parameters or calling, we will learn m...
1. Introduction to Functions
1.1 What are Functions? Functions are self-contained blocks of code that perform specific tasks. They are fundamental building blocks that help organize code, promote reusability, and make programs more modular and maintainable. Benefits of Functions: Code Re...
2. Function Declaration, Definition, and Calling
2.1 Function Anatomy A C function consists of several parts: return_type function_name(parameter_list) { // Function body // Local variables // Statements return value; // (if return_type is not void) } Components: Return Type: Data type of t...
3. Parameters and Arguments
3.1 Terminology Parameters (Formal Parameters): Variables in the function definition Arguments (Actual Parameters): Values passed when calling the function // 'a' and 'b' are parameters int add(int a, int b) { return a + b; } int main() { int x = 5,...
4. Return Statement
4.1 Basic Return Usage The return statement serves two purposes: Return control to the calling function Return a value (optional, depending on function type) // Function that returns a value int get_maximum(int a, int b) { if (a > b) { return a; ...
5. Variable Scope and Lifetime
5.1 Local Variables Variables declared inside a function are local to that function: Scope: Only accessible within the function where they're declared Lifetime: Created when function is called, destroyed when function returns Storage: Usually on the stack #i...
6. Bonus: Some C Library Functions
Throughout this module, we've focused on defining our own functions. However, C also provides a rich set of built-in functions, known as Standard Library Functions. These functions are pre-written and grouped into various libraries (e.g., <stdio.h>, <stdlib.h>...
7. Recursion
7.1 Understanding Recursion Recursion is a programming technique where a function calls itself. Every recursive function needs: Base case: Condition that stops the recursion Recursive case: Function calls itself with modified parameters 7.2 Python vs C Recur...
8. Function Examples and Applications
8.1 Menu-Driven Program #include <stdio.h> // Function prototypes void display_menu(void); int get_choice(void); void calculator_add(void); void calculator_multiply(void); void display_table(int num); int main() { int choice; do { displa...
9. Common Errors and Debugging
9.1 Function Declaration Errors Error 1: Missing Function Prototype // ERROR: Function used before declaration int main() { int result = add_numbers(5, 3); // Error: 'add_numbers' not declared return 0; } int add_numbers(int a, int b) { return a ...
1. Introduction: From Python Lists to C Arrays
1.1 Key Differences Overview Aspect Python Lists C Arrays Size Dynamic (can grow/shrink) Fixed size (static) Type Can store mixed types Single type only Memory Automatic management Manual bounds checking Declaration list = [1, 2, 3] int arr[5] = {...
2. Array Declaration and Initialization
2.1 Basic Array Declaration Python vs C Comparison: Python C numbers = [1, 2, 3, 4, 5] int numbers[5] = {1, 2, 3, 4, 5}; grades = [] float grades[100]; name = "Alice" char name[10] = "Alice"; C Array Declaration Syntax: data_type array_name[size]...