0% found this document useful (0 votes)
3 views7 pages

C PROGRAMMING M1

Module 1 covers basic programming concepts in C, including sequential, conditional, unconditional control structures, and looping structures. It also introduces preprocessing, modular programming, functions, storage classes, and recursion, providing examples and real-life analogies for better understanding. Each section emphasizes the importance of these concepts in writing efficient and organized code.

Uploaded by

Mohammed Jisam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

C PROGRAMMING M1

Module 1 covers basic programming concepts in C, including sequential, conditional, unconditional control structures, and looping structures. It also introduces preprocessing, modular programming, functions, storage classes, and recursion, providing examples and real-life analogies for better understanding. Each section emphasizes the importance of these concepts in writing efficient and organized code.

Uploaded by

Mohammed Jisam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

📘 Module 1: Basic Programming Concepts in C

🎯sequential,
CO1: Make use of the basic programming concepts –
conditional, unconditional, looping structures and
functions in C

🔹 M1.01: Basic Programming Concepts


✅ 1. Sequential Structure
Meaning: Instructions are executed one after another, in the order they are
written.

Why Important?: This is the foundation of any program. Every C program


starts with sequential execution.

Real-life Example: Making tea – Boil water → Add tea powder → Add sugar →
Pour into cup.

C Example:

int a = 10;
int b = 20;
int sum = a + b;
printf("Sum = %d", sum);

🔄 2. Conditional Structure
Meaning: Executes a block of code only if a specific condition is true.

Used to make decisions in a program.

Key keywords: if , else , else if , switch .

Real-life Example: "If it rains, take an umbrella."

C Example:

Untitled 1
int marks = 80;
if(marks > 50){
printf("You Passed!");
} else {
printf("Try Again");
}

🔃 3. Unconditional Control Structure


Meaning: Transfers control from one part of the program to another without
checking any condition.

Used for breaking loops, skipping iterations, or exiting functions.

Keywords: goto , break , continue , return .

Examples:

break : Exit a loop early

continue : Skip one iteration

goto : Jump to a specific label

return : Exit from a function

for(int i = 0; i < 5; i++){


if(i == 3) break;
printf("%d\n", i);
}

🔁 4. Looping Structure (Repetition)


Meaning: A way to repeat a block of code multiple times.

Types:

for : Known number of repetitions.

while : Condition checked before loop.

Untitled 2
do-while : Condition checked after loop (runs at least once).

Example:

for(int i = 1; i <= 5; i++){


printf("%d\n", i);
}

Real-life Example: A clock keeps ticking until you turn it off.

🔹 M1.02: Preprocessing in C
🛠️ Preprocessor
A preprocessor runs before the actual compilation.

It modifies the code before the compiler sees it.

🧩 1. File Inclusion
Syntax: #include <filename>

Includes other files into the current file.

Most common use: #include <stdio.h> – adds standard input/output functions.

🔁 2. Macro Substitution
Replaces a name with a value throughout the program.

Syntax: #define PI 3.14

Reduces repetition, increases readability.

#define PI 3.14
float area = PI * r * r;

🔹 M1.03: Modular Programming in C


🧱 Modular Programming
Untitled 3
Breaking a big program into smaller parts called functions (modules).

Each function performs one specific task.

Helps in:

Easy debugging

Reusing code

Better team development

Real-life Example: In a restaurant, different chefs handle starters, main course,


and desserts.

🔹 M1.04: Functions in C
🔹1. Function Declaration
Tells the compiler the function’s name, return type, and parameters.

Placed before main()

int add(int, int);

🔹2. Function Definition


Actual code written for the function.

int add(int a, int b){


return a + b;
}

🔹3. Function Call


Invokes the function to perform the task.

int result = add(5, 10);

Untitled 4
🔹 M1.05: Storage Class, Lifetime, Visibility
🔐 Storage Classes
Controls 4 things:

Storage location

Default initial value

Scope (where it's accessible)

Lifetime (how long it exists)

Storage Class Scope Lifetime Default Value

auto Local Function block Garbage value

static Local Entire program 0

extern Global Entire program 0

register Local Function block Garbage value

Example:

void test() {
static int count = 0;
count++;
printf("%d\n", count);
}

🔹 M1.06: Programs Using Storage Class and Scope


📌 Example: static

void demo() {
static int a = 0;
a++;
printf("%d\n", a);
}

Untitled 5
Output remains: 1, 2, 3,... on each call because static keeps the value between
calls.

📌 Example: extern
Declare a variable in one file, use in another using extern .

🔹 M1.07: Recursion in C
🔁 Recursion
A function that calls itself.

Used when the problem can be broken into smaller sub-problems of the same
type.

Rules:

Must have a base condition to stop the recursion.

Each call works on a smaller version of the problem.

Example: Factorial

int fact(int n){


if(n == 0)
return 1;
else
return n * fact(n-1);
}

🔹 M1.08: Programs Using Recursion


📌 Examples:
Factorial:

int fact(int n) {
if (n == 0) return 1;

Untitled 6
else return n * fact(n-1);
}

Fibonacci:

int fib(int n){


if(n == 0) return 0;
if(n == 1) return 1;
return fib(n-1) + fib(n-2);
}

Would you like this to be converted into a PDF with headings, formatted code, and
examples for your students?

Untitled 7

You might also like