C Programming Full Course for free ⚙️ (2025)

C Programming Full Course for free ⚙️ (2025)

Brief Summary

This comprehensive C programming tutorial covers everything from setting up your coding environment to building practical projects like a clock. It explains essential concepts such as variables, data types, format specifiers, arithmetic operations, user input, conditional statements (if/else and switch), loops (while and for), functions, pointers, file I/O, and dynamic memory allocation. The tutorial also includes hands-on projects like a shopping cart, Mad Libs game, weight converter, temperature converter, compound interest calculator, number guessing game, rock paper scissors, banking program and digital clock to reinforce learning.

  • Setting up a C coding environment with Visual Studio Code and a C compiler.
  • Understanding variables, data types (int, float, double, char, bool), and format specifiers.
  • Implementing conditional statements (if/else and switch) and loops (while and for) for decision-making and repetition.
  • Creating and using functions, including passing arguments and returning values.
  • Working with pointers for efficient memory management.
  • Performing file input/output operations.
  • Implementing dynamic memory allocation with malloc, calloc, and realloc.
  • Building practical projects to reinforce learning.

Introduction

The video introduces a comprehensive C programming tutorial that includes 12 hands-on projects, culminating in the creation of a working clock. It skips lengthy introductions and immediately dives into the essentials needed to start coding in C.

Installing an IDE

To begin coding in C, you need an Integrated Development Environment (IDE) and a C compiler. The IDE is a workspace for writing code, and the C compiler converts the code into machine code that the computer can understand. The tutorial guides you through downloading and installing Visual Studio Code from code.visualstudio.com, selecting the appropriate version for your operating system.

Setting Up Visual Studio Code

After installing Visual Studio Code, create a new project folder named "coding" (or any name you prefer) on your desktop. Then, create a new C file named "main.c" within this folder. The tutorial recommends installing the C/C++ extension pack and the CodeRunner extension for quality-of-life improvements. Enable the "clear previous output" and "save file before run" settings in CodeRunner for a smoother experience.

Checking for and Installing a C Compiler

The video explains how to check if a C compiler is already installed on Windows, Mac, and Linux operating systems, providing specific commands for each. For Windows users needing to install a compiler, the tutorial recommends downloading MSYS2 from msys2.org and following the installation instructions. This involves using the MSYS2 software to download the C compiler by running the command pacman -S --needed base-devel mingw-w64-x86_64-toolchain. After installation, the path variable needs to be set to include the location of the GCC compiler (e.g., C:\msys64\ucrt64\bin) so that the operating system can find it.

Your First C Program

The initial C program includes the statement #include <stdio.h>, a pre-processor directive that incorporates the standard input/output library, essential for displaying text. The main function, int main(), serves as the program's entry point and is required for the program to run. The return 0; statement at the end of the main function indicates successful program execution. The printf statement is used to print text to the screen, with \n adding a new line. Comments are added using // for single-line comments and /* ... */ for multi-line comments.

Variables

A variable is a reusable container for a value, behaving as if it were the value it contains. Different data types exist, including int for integers (whole numbers), float for floating-point numbers (decimals), double for high-precision decimals, char for single characters (enclosed in single quotes), and arrays of characters (strings, enclosed in double quotes). Booleans (bool) are either true or false, requiring the stdbool.h header file. Format specifiers (e.g., %d for int, %f for float, %c for char, %s for string) are used within printf to display variables.

Format Specifiers

Format specifiers are special tokens that begin with a percent symbol (%) followed by a character that specifies the data type, along with optional modifiers for width, precision, and flags. Common data types include integers (%d), floats (%f), doubles (%f or %lf), chars (%c), and strings (%s). Optional modifiers can be added between the percent sign and the data type character to format the output, such as setting the width (e.g., %3d), left-justifying values (e.g., %-3d), adding leading zeros (e.g., %03d), displaying plus signs for positive numbers (e.g., %+d), and setting the precision for floating-point numbers (e.g., %.2f).

Basic Arithmetic

Basic arithmetic operators in C include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). The modulus operator (%) gives the remainder of a division. Increment (++) and decrement (--) operators increase or decrease a variable by one. Augmented assignment operators (e.g., +=, -=, *=, /=) provide a shortcut for reassigning the same variable. Integer division truncates the decimal portion, while floating-point division retains it.

User Input

To accept user input in C, use the scanf function. For VS Code users, enable "Run in Terminal" in the CodeRunner extension settings. Use format specifiers (e.g., %d for int, %f for float, %c for char, %s for string) with scanf to read input into variables. The address-of operator (&) is used to specify the memory location of the variable. To read strings with spaces, use fgets instead of scanf. Clear the input buffer with getchar() or by adding a space before the format specifier in scanf to avoid issues with newline characters. Remove the newline character from strings read with fgets using strLen and a null terminator.

Shopping Cart Program

The shopping cart program takes user input for the name of an item, its price, and the quantity. It calculates the total cost and displays the information. The program uses fgets to read the item name, scanf to read the price and quantity, and arithmetic operators to calculate the total. Format specifiers are used to display the output with appropriate formatting. The program also removes the newline character from the item name using strLen and a null terminator.

Mad Libs Game

The Mad Libs game prompts the user to enter various words (nouns, verbs, adjectives) and then inserts those words into a pre-written story. The program uses fgets to read the user's input and printf to display the completed story. The program also removes the newline character from the user's input using strLen and a null terminator.

Math Functions

The math.h header file provides various math functions, including sqrt (square root), pow (power), round (round to nearest integer), ceil (round up), floor (round down), abs (absolute value), log (natural logarithm), sin (sine), cos (cosine), and tan (tangent). These functions can be used to perform mathematical operations in C programs.

Area, Surface Area, and Volume Calculator

The program calculates the area of a circle, the surface area of a sphere, and the volume of a sphere, given a radius as input. The program uses the math.h header file for the pow function and defines a constant for pi. The program uses scanf to read the radius, arithmetic operators to perform the calculations, and format specifiers to display the output with appropriate formatting.

Compound Interest Calculator

The compound interest calculator calculates the total amount after a specified number of years, given the principal, interest rate, and number of times compounded per year. The program uses the math.h header file for the pow function and scanf to read the user's input. The program uses arithmetic operators to perform the calculations and format specifiers to display the output with appropriate formatting.

If Statements

If statements allow for basic decision-making in programming. The if statement executes a block of code if a condition is true. The else statement executes a block of code if the condition is false. The else if statement allows for checking multiple conditions. Nested if statements allow for more complex decision-making. The order of conditions matters, as the first true condition will be executed. If statements can be used with boolean variables and strings.

Weight Converter Program

The weight converter program converts between kilograms and pounds. The program prompts the user to select a conversion option (kilograms to pounds or pounds to kilograms) and then enters the weight. The program uses if statements to determine the conversion direction and performs the appropriate calculation. The program uses scanf to read the user's input and format specifiers to display the output with appropriate formatting.

Temperature Conversion Program

The temperature conversion program converts between Celsius and Fahrenheit. The program prompts the user to select a conversion option (Celsius to Fahrenheit or Fahrenheit to Celsius) and then enters the temperature. The program uses if statements to determine the conversion direction and performs the appropriate calculation. The program uses scanf to read the user's input and format specifiers to display the output with appropriate formatting.

Switches

A switch statement is an alternative to using many if and else if statements. It is more efficient when working with fixed integer values and improves readability. The switch statement examines a value against matching cases. The break statement is used to exit the switch. The default case is executed if no other cases match. Switches can be used with integers and characters.

Nested If Statements

Nested if statements are if statements inside other if statements. They allow for more complex decision-making. The example program sells movie tickets with discounts for students and seniors, using nested if statements to determine the appropriate discount.

Calculator Program

The calculator program takes two numbers and an operator as input and performs the corresponding arithmetic operation. The program uses a switch statement to determine the operation to perform. Nested if statements are used to handle division by zero. The program uses scanf to read the user's input and format specifiers to display the output with appropriate formatting.

Logical Operators

Logical operators are used to combine or modify boolean expressions. The and operator (&&) requires both conditions to be true. The or operator (||) requires at least one condition to be true. The not operator (!) reverses a boolean expression.

Functions

Functions are reusable sections of code that can be invoked (called). They help avoid repetition and improve code organization. Functions have a return type, a name, and a set of parameters. Arguments are passed to functions when they are called. Function prototypes provide information about a function's name, return type, and parameters before the function is defined.

Return Keyword

The return keyword returns a value from a function back to the calling code. The return type of the function must match the data type of the returned value. The return keyword can also be used to exit a function prematurely.

Variable Scope

Variable scope refers to where a variable is recognised and accessible. Variables can share the same name if they are within different scopes. Local scope refers to variables declared within a function or block of code. Global scope refers to variables declared outside of any function. It is generally best practice to avoid global variables.

Function Prototypes

A function prototype is a declaration of a function that specifies its name, return type, and parameters. Function prototypes allow functions to be used before they are defined, improve code readability and organisation, and enable type checking.

While Loops

A while loop continues executing a block of code as long as a specified condition remains true. It's important to avoid infinite loops by ensuring the condition eventually becomes false. A do-while loop is a variation that executes the block of code at least once before checking the condition.

For Loops

A for loop is used to repeat a block of code a limited number of times. It consists of three optional steps: initialisation, condition, and update. The initialisation step sets up a counter variable. The condition step determines when the loop should stop. The update step modifies the counter variable after each iteration.

Break and Continue

The break keyword is used to exit a loop prematurely. The continue keyword is used to skip the current iteration of a loop and proceed to the next iteration.

Nested Loops

A nested loop is a loop inside another loop. Nested loops are useful for iterating over two-dimensional data structures, such as matrices or grids. The outer loop controls the rows, and the inner loop controls the columns.

Random Numbers

To generate pseudo-random numbers in C, include the stdlib.h and time.h header files. Use the srand function to seed the random number generator with the current time. Use the rand function to generate a pseudo-random number. Use the modulus operator (%) to limit the range of the random number.

Number Guessing Game

The number guessing game generates a random number between a specified range and prompts the user to guess the number. The program uses a do-while loop to continue the game until the user guesses the correct number. The program provides feedback to the user (too high or too low) after each incorrect guess.

Rock Paper Scissors Game

The rock paper scissors game allows the user to play against the computer. The program generates a random choice for the computer and prompts the user to select their choice. The program uses if statements to determine the winner and displays the result.

Banking Program

The banking program allows the user to check their balance, deposit money, withdraw money, and exit the program. The program uses a do-while loop to continue the program until the user selects the exit option. The program uses a switch statement to handle the different menu options.

Typedef

typedef is a keyword in C that allows you to create an alias (nickname) for an existing data type. This can simplify complex type declarations and improve code readability.

Enums

Enums (enumerations) are user-defined data types that consist of a set of named integer constants. Enums provide a way to represent a set of related values with meaningful names, improving code readability and maintainability.

Structs

Structs are custom data types that group together related variables (members) of different data types. Structs are similar to objects in other programming languages and provide a way to create custom data structures.

Arrays of Structs

An array of structs is an array where each element is a struct. This allows you to store and manage multiple related data structures in an organised way.

Pointers

A pointer is a variable that stores the memory address of another variable. Pointers allow you to pass the address of a large data structure instead of copying the entire data, saving memory. Pointers are declared using the asterisk () symbol. The address-of operator (&) is used to get the memory address of a variable. The dereference operator () is used to access the value stored at a memory address.

File I/O: Writing to a File

To create and write to a file in C, use the fopen function to open the file in write mode ("w"). Use the fprintf function to write data to the file. Use the fclose function to close the file when you are finished with it.

File I/O: Reading a File

To read a file in C, use the fopen function to open the file in read mode ("r"). Use the fgets function to read data from the file into a buffer. Use the fclose function to close the file when you are finished with it.

Malloc Function

malloc (memory allocation) is a function in C that dynamically allocates a specified number of bytes in memory. It returns a pointer to the allocated memory. It's important to free the allocated memory when you are finished with it using the free function to prevent memory leaks.

Calloc Function

calloc (contiguous allocation) is a function in C that dynamically allocates memory and sets all allocated bytes to zero. It takes two arguments: the number of elements and the size of each element.

Realloc Function

realloc (reallocation) is a function in C that resizes previously allocated memory. It takes two arguments: a pointer to the old memory and a new size in bytes. It returns a pointer to the reallocated memory.

Share

Summarize Anything ! Download Summ App

Download on the Apple Store
Get it on Google Play
© 2024 Summ