Complete C Programming course is made for beginners who want a strong programming foundation
C Programming Full Course
This complete C Programming course is made for beginners who want a strong programming foundation. You will learn installation, syntax, variables, operators, conditions, loops, arrays, strings, functions, recursion, pointers, structures, file handling, dynamic memory, and final projects.
Course Contents
1. What is C Programming?2. Installation and Setup3. First C Program4. Variables and Data Types5. Input and Output6. Operators7. Conditions8. Loops9. Arrays10. Strings11. Functions12. Recursion13. Pointers14. Structures and Unions15. File Handling16. Dynamic Memory Allocation17. Preprocessor and Header Files18. Common Mistakes19. Final Projects20. Final Questions and Answers1. What is C Programming?
C is a powerful general-purpose programming language used for system programming, embedded systems, operating systems, compilers, device drivers, and performance-focused software.
C teaches memory, variables, loops, functions, and pointers clearly.
C is close to hardware and gives high performance.
Operating systems and embedded devices commonly use C.
C helps you learn C++, Java, data structures, and computer architecture.
Where C is Used
- Operating systems
- Embedded systems
- Microcontrollers
- Game engines
- Compilers
- Database systems
- Network tools
Practice
Write 5 devices or software systems where C programming can be useful.
Quiz 1
C is commonly used for:
2. Installation and Setup
Tools Needed
- C compiler: GCC, MinGW, Clang, or Code::Blocks compiler
- Editor: VS Code, Code::Blocks, Dev-C++, or any IDE
- Terminal or Command Prompt
Check GCC
gcc --versionCompile and Run
gcc main.c -o main
./mainWindows:
gcc main.c -o main.exe
main.exePractical Task
- Install a C compiler.
- Create
main.c. - Compile and run the first program.
Quiz 2
Which command checks GCC version?
3. First C Program
Hello World
#include <stdio.h>
int main() {
printf("Hello, C Programming!");
return 0;
}| Code | Meaning |
|---|---|
| #include <stdio.h> | Standard input/output library |
| int main() | Program starts here |
| printf() | Prints output |
| return 0; | Successful ending |
Comments
// Single line comment
/* Multi-line comment */Practical Task
#include <stdio.h>
int main() {
printf("Name: Kumar\n");
printf("Age: 20\n");
printf("Course: C Programming\n");
return 0;
}Quiz 3
Which function prints output in C?
4. Variables and Data Types
A variable is a named memory location used to store data.
int age = 20;
float price = 99.50;
double salary = 50000.75;
char grade = 'A';| Type | Use | Format |
|---|---|---|
| int | Whole number | %d |
| float | Decimal | %f |
| double | Large decimal | %lf in scanf |
| char | Character | %c |
#include <stdio.h>
int main() {
int age = 21;
float marks = 85.5;
char grade = 'A';
printf("Age: %d\n", age);
printf("Marks: %.2f\n", marks);
printf("Grade: %c\n", grade);
return 0;
}Practical Task
Create variables for product price, quantity, and grade. Print them.
Quiz 4
Which data type stores a single character?
5. Input and Output
scanf() takes input from the user.
#include <stdio.h>
int main() {
int age;
printf("Enter age: ");
scanf("%d", &age);
printf("Your age is %d", age);
return 0;
}& gives the memory address of the variable. scanf() needs the address to store input.#include <stdio.h>
int main() {
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
printf("Sum = %d", a + b);
return 0;
}Practical Task
Take name, age, and marks as input and print a student report.
Quiz 5
Which function takes input in C?
6. Operators
| Operator | Meaning |
|---|---|
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| % | Remainder |
| == | Equal |
| != | Not equal |
| && | AND |
| || | OR |
#include <stdio.h>
int main() {
int a = 10, b = 3;
printf("Add: %d\n", a + b);
printf("Remainder: %d\n", a % b);
printf("Is a greater? %d\n", a > b);
return 0;
}Practical Task
Create a simple calculator using arithmetic operators.
Quiz 6
Which operator gives remainder?
7. Conditions
if else
#include <stdio.h>
int main() {
int age;
printf("Enter age: ");
scanf("%d", &age);
if (age >= 18) {
printf("Adult");
} else {
printf("Not adult");
}
return 0;
}else if
if (marks >= 75) {
printf("A Grade");
} else if (marks >= 65) {
printf("B Grade");
} else if (marks >= 50) {
printf("C Grade");
} else {
printf("Fail");
}switch
switch(day) {
case 1: printf("Monday"); break;
case 2: printf("Tuesday"); break;
default: printf("Invalid day");
}Practical Task
Check whether a number is positive, negative, or zero.
Quiz 7
Which keyword is used for multiple choices?
8. Loops
for Loop
for (int i = 1; i <= 5; i++) {
printf("%d\n", i);
}while Loop
int i = 1;
while (i <= 5) {
printf("%d\n", i);
i++;
}do while
int i = 1;
do {
printf("%d\n", i);
i++;
} while (i <= 5);Multiplication Table
#include <stdio.h>
int main() {
int number;
printf("Enter number: ");
scanf("%d", &number);
for (int i = 1; i <= 12; i++) {
printf("%d x %d = %d\n", number, i, number * i);
}
return 0;
}Quiz 8
Which loop runs at least once?
9. Arrays
An array stores multiple values of the same data type.
int marks[5] = {75, 80, 65, 90, 85};
printf("%d", marks[0]);Loop Through Array
int marks[5] = {75, 80, 65, 90, 85};
for (int i = 0; i < 5; i++) {
printf("%d\n", marks[i]);
}Total and Average
#include <stdio.h>
int main() {
int marks[5], total = 0;
float average;
for (int i = 0; i < 5; i++) {
printf("Enter mark %d: ", i + 1);
scanf("%d", &marks[i]);
total += marks[i];
}
average = total / 5.0;
printf("Total = %d\n", total);
printf("Average = %.2f", average);
return 0;
}Quiz 9
Array index starts from:
10. Strings
In C, a string is an array of characters ending with \0.
char name[20] = "Ravi";
printf("Name: %s", name);Read Full Line
char sentence[100];
fgets(sentence, sizeof(sentence), stdin);
printf("%s", sentence);String Functions
#include <string.h>
char text[50] = "Hello";
printf("Length: %lu", strlen(text));| Function | Use |
|---|---|
| strlen() | Find length |
| strcpy() | Copy string |
| strcat() | Join strings |
| strcmp() | Compare strings |
Quiz 10
Which header is used for string functions?
11. Functions
A function is a reusable block of code.
return_type function_name(parameters) {
// code
}Function with Return
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int main() {
int result = add(10, 20);
printf("Result = %d", result);
return 0;
}Calculator Functions
int add(int a, int b) { return a + b; }
int sub(int a, int b) { return a - b; }
int mul(int a, int b) { return a * b; }Practical Task
Create functions for addition, subtraction, multiplication, and division.
Quiz 11
A function is used to:
12. Recursion
Recursion means a function calls itself. It must have a base condition.
#include <stdio.h>
int factorial(int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
int main() {
int n;
printf("Enter number: ");
scanf("%d", &n);
printf("Factorial = %d", factorial(n));
return 0;
}Quiz 12
Recursion needs a base condition to:
13. Pointers
A pointer is a variable that stores the memory address of another variable.
#include <stdio.h>
int main() {
int number = 10;
int *ptr = &number;
printf("Value: %d\n", number);
printf("Address: %p\n", &number);
printf("Pointer stores: %p\n", ptr);
printf("Pointed value: %d\n", *ptr);
return 0;
}Pointer with Function
void changeValue(int *x) {
*x = 100;
}- Pointers help with arrays and strings.
- Pointers allow functions to modify variables.
- Pointers are needed for dynamic memory and data structures.
Quiz 13
A pointer stores:
14. Structures and Unions
A structure groups different data types under one name.
#include <stdio.h>
struct Student {
int id;
char name[50];
float marks;
};
int main() {
struct Student s1 = {1, "Ravi", 85.5};
printf("%d %s %.2f", s1.id, s1.name, s1.marks);
return 0;
}Union
A union shares memory among members. Usually one value is meaningful at a time.
union Data {
int i;
float f;
char ch;
};| Structure | Union |
|---|---|
| Separate memory for members | Shared memory |
| Stores all values | Usually one value at a time |
Quiz 14
A structure is used to:
15. File Handling
File handling stores data permanently in files.
| Mode | Meaning |
|---|---|
| r | Read |
| w | Write |
| a | Append |
| r+ | Read and write |
Write File
#include <stdio.h>
int main() {
FILE *file = fopen("notes.txt", "w");
if (file == NULL) {
printf("File error");
return 1;
}
fprintf(file, "C file handling example.");
fclose(file);
return 0;
}Read File
FILE *file = fopen("notes.txt", "r");
char text[100];
fgets(text, sizeof(text), file);
printf("%s", text);
fclose(file);Quiz 15
Which function opens a file in C?
16. Dynamic Memory Allocation
Dynamic memory allocation allocates memory during program execution. Use stdlib.h.
| Function | Use |
|---|---|
| malloc() | Allocates memory |
| calloc() | Allocates and initializes memory to zero |
| realloc() | Changes memory size |
| free() | Releases memory |
#include <stdio.h>
#include <stdlib.h>
int main() {
int *ptr, n;
printf("Enter number of elements: ");
scanf("%d", &n);
ptr = (int*) malloc(n * sizeof(int));
if (ptr == NULL) {
printf("Memory not allocated");
return 1;
}
for (int i = 0; i < n; i++) {
scanf("%d", &ptr[i]);
}
free(ptr);
return 0;
}free() after dynamic memory use.Quiz 16
Which function releases dynamically allocated memory?
17. Preprocessor and Header Files
Preprocessor directives start with # and run before compilation.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>#define
#include <stdio.h>
#define PI 3.14159
int main() {
float r = 5;
printf("Area = %.2f", PI * r * r);
return 0;
}| Header | Use |
|---|---|
| stdio.h | Input and output |
| stdlib.h | Memory and utility functions |
| string.h | String functions |
| math.h | Math functions |
| ctype.h | Character functions |
Quiz 17
Preprocessor directives start with:
18. Common C Programming Mistakes
Missing Semicolon
printf("Hello") // wrong
printf("Hello"); // correctForgetting & in scanf
scanf("%d", age); // wrong
scanf("%d", &age); // correctArray Out of Bounds
int a[5];
a[5] = 10; // wrong, valid indexes are 0 to 4Infinite Loop
while (i < 5) {
printf("%d", i);
// missing i++
}Uninitialized Variable
int total;
total = total + 10; // wrong, garbage valueQuiz 18
In scanf(), normal variables usually need:
19. Final Practical Projects
Student Grade System
#include <stdio.h>
int main() {
char name[50];
int marks;
printf("Enter student name: ");
scanf("%s", name);
printf("Enter marks: ");
scanf("%d", &marks);
printf("Name: %s\n", name);
if (marks >= 75) printf("Grade: A");
else if (marks >= 65) printf("Grade: B");
else if (marks >= 50) printf("Grade: C");
else printf("Grade: Fail");
return 0;
}Simple Calculator
#include <stdio.h>
int main() {
double a, b;
char op;
printf("Enter operator (+, -, *, /): ");
scanf("%c", &op);
printf("Enter two numbers: ");
scanf("%lf %lf", &a, &b);
switch(op) {
case '+': printf("%.2lf", a + b); break;
case '-': printf("%.2lf", a - b); break;
case '*': printf("%.2lf", a * b); break;
case '/':
if (b != 0) printf("%.2lf", a / b);
else printf("Cannot divide by zero");
break;
default: printf("Invalid operator");
}
return 0;
}Bank Account System
#include <stdio.h>
int main() {
double balance = 0, amount;
int choice;
while (1) {
printf("\n1.Deposit 2.Withdraw 3.Balance 4.Exit\nChoose: ");
scanf("%d", &choice);
if (choice == 1) {
scanf("%lf", &amount);
balance += amount;
} else if (choice == 2) {
scanf("%lf", &amount);
if (amount <= balance) balance -= amount;
else printf("Insufficient balance");
} else if (choice == 3) {
printf("Balance = %.2lf", balance);
} else if (choice == 4) break;
else printf("Invalid choice");
}
return 0;
}Student Record Using Structure
#include <stdio.h>
struct Student {
int id;
char name[50];
float marks;
};
int main() {
struct Student s[3];
for (int i = 0; i < 3; i++) {
scanf("%d %s %f", &s[i].id, s[i].name, &s[i].marks);
}
for (int i = 0; i < 3; i++) {
printf("%d %s %.2f\n", s[i].id, s[i].name, s[i].marks);
}
return 0;
}Contact Book File Project
#include <stdio.h>
int main() {
FILE *file = fopen("contacts.txt", "w");
char name[50], phone[20];
int n;
if (file == NULL) return 1;
printf("How many contacts? ");
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s %s", name, phone);
fprintf(file, "%s %s\n", name, phone);
}
fclose(file);
return 0;
}Project Quiz
Which project is best to practice structures?
20. Final Questions and Answers
Important C Questions
Q1: What is C programming?
A: C is a general-purpose programming language used for system software, embedded systems, and performance-focused applications.
Q2: What is a variable?
A: A variable is a named memory location used to store data.
Q3: What is the use of printf()?
A: It displays output.
Q4: What is the use of scanf()?
A: It takes input from the user.
Q5: What is an array?
A: An array stores multiple values of the same data type.
Q6: What is a string in C?
A: A string is an array of characters ending with \0.
Q7: What is a function?
A: A reusable block of code.
Q8: What is recursion?
A: A function calling itself.
Q9: What is a pointer?
A: A variable that stores a memory address.
Q10: What is a structure?
A: A user-defined data type that groups different data types.
Q11: What is file handling?
A: Reading and writing data to files.
Q12: What is dynamic memory allocation?
A: Allocating memory during runtime using malloc(), calloc(), and related functions.
Final Practical Exam
- Check odd or even number.
- Find largest of three numbers.
- Print multiplication table.
- Reverse an array.
- Find string length.
- Calculator using functions.
- Factorial using recursion.
- Swap two numbers using pointers.
- Student record using structure.
- Store contacts in a file.
Final Quiz
The best way to become strong in C programming is:
Join the conversation