1
Example 1 — Variables and Input
0 – 10 min
This example reads two numbers and prints their sum.
#include <stdio.h> int main() { int a, b; printf("Enter two numbers: "); scanf("%d %d", &a, &b); printf("Sum = %d\n", a + b); return 0; }
2
Example 2 — Arrays and Loops
10 – 20 min
This example stores marks in an array and prints all values using a loop.
#include <stdio.h> int main() { int marks[5] = {85, 90, 78, 88, 92}; for (int i = 0; i < 5; i++) { printf("%d ", marks[i]); } printf("\n"); return 0; }
Idea: Arrays are useful when you need to store many values of the same type.
3
Example 3 — Strings and Functions
20 – 30 min
This example uses a function to display a string.
#include <stdio.h> #include <string.h> void showName(char name[]) { printf("Hello, %s\n", name); } int main() { char name[50] = "Aman"; showName(name); return 0; }
⚠️ Note: Strings in C are character arrays ending with
\0.4
Example 4 — Structures
30 – 40 min
Structures group related data like a student's roll number, name, and marks.
#include <stdio.h> struct Student { int roll; char name[50]; float marks; }; int main() { struct Student s1 = {1, "Sara", 91.5}; printf("%d %s %.2f\n", s1.roll, s1.name, s1.marks); return 0; }
5
Example 5 — Pointers
40 – 50 min
This example changes a variable using a pointer.
#include <stdio.h> void change(int *x) { *x = 100; } int main() { int a = 10; change(&a); printf("a = %d\n", a); return 0; }
Pointer rule: Use
& to get an address and * to access the value at that address.comparison
| Example | Main Concept | What It Does |
|---|---|---|
| 1 | Variables | Adds two numbers |
| 2 | Arrays + Loops | Prints all marks |
| 3 | Strings + Functions | Prints a greeting |
| 4 | Structures | Stores student data |
| 5 | Pointers | Changes a value directly |
Q
Quick Quiz
Question 1 of 5
Which concept stores many values of the same type?
Question 2 of 5
Which symbol is used to get the address of a variable?
Question 3 of 5
What does a function do?
Question 4 of 5
Which concept groups different data types together?
Question 5 of 5
Which operator gives the value stored at an address?
✓
Lesson Checklist
- I understand variables and input
- I understand arrays and loops
- I understand strings and functions
- I understand structures
- I understand pointers
- I reviewed all 5 examples
- I can write a similar program myself