LMNsC Programming (original) (raw)

LMNs-C Programming

Last Updated : 23 Jul, 2025

C programming is a powerful and widely-used programming language that forms the backbone of many modern technologies. Known for its simplicity and efficiency, it is the foundation for learning advanced programming concepts. C programming is a powerful and widely-used programming language that forms the backbone of many modern technologies. Known for its simplicity and efficiency, it is the foundation for learning advanced programming concepts. This "Last Minute Notes" article is designed to provide a quick and concise revision of the key topics in C programming, including data types, operators, control flow statements, functions, and storage classes.

Table of Content

Data Types and Operators

Data Types

1. Primitive Data Type

(a) Integer Types:

(b) Character Types:

(c) Floating Types:

(d) Other:

2. Non – Primitive Data Type

(a) Derived data type:

(b) User-defined data type:

**Note:

read more about - Data Types

Operators

**Arithmetic Operators

Used for mathematical calculations:

**2. Relational Operators

Used to compare two values, returning true (1) or false (0):

**3. Logical Operators

Used for logical conditions, returning true (1) or false (0):

**4. Assignment Operator

Used to assign values:

Example: int a = 5;

**5. Increment and Decrement Operators

Used to increase or decrease a value by 1:

Example:

int x = 5;
printf("%d", ++x); // Outputs 6

**6. Bitwise Operators

Operate at the bit level:

Example:

int a = 5; // Binary: 0101
int b = a << 1; // Result: 1010 (Decimal 10)

**7. Ternary Operator

A shorthand for if-else:

condition ? value_if_true : value_if_false

Example:

int a = 10, b = 5;
int max = (a > b) ? a : b; // Assigns the larger value to max

operators

C Operators and Their Associativity.

read more about - Operators

Control Flow Statements

A) Decision-Making Statements

1. If Statement

Executes a block of code if a condition is true.
Syntax:

if (condition) {
// statements to execute if condition is true
}

2. If-Else Statement

Executes one block if the condition is true; another block if false.
Syntax:

if (condition) {
// statements if condition is true
}
else {
// statements if condition is false
}

3. Else-If Ladder

Used when multiple conditions need to be tested.
Syntax:

if (condition1) {
// statements
} else if (condition2) {
// statements
} else {
// default statements
}

4. Switch Statement

Selects one of many blocks of code to execute based on a specific value.
Syntax:

switch (expression) {
case value1: // statements

break;
case value2: // statements

break;
default: // default statements
}

B) Looping Statements

1. For Loop

The for statement evaluates 3 expressions and executes the loop body until second controlling expression executes to false. It is recommended to use for loop when the number of iterations is known in advance.
Syntax:

for (initialization; condition; increment/decrement) {
// statements
}

2. While Loop

while (condition) {
// statements
}

3. Do-While Loop

do {
// statements
} while (condition);

**C) Jump Statements

1. Break Statement

Exits the nearest enclosing loop or switch statement.
Example:

for (int i = 1; i <= 5; i++) {
if (i == 3) break;
printf("%d\n", i);
}

2. Continue Statement

Skips the rest of the current loop iteration and moves to the next iteration.
Example:

for (int i = 1; i <= 5; i++) {
if (i == 3) continue;
printf("%d\n", i);
}

3. Goto Statement

Transfers control to a labeled statement.
Example:

int i = 1;
start: if (i <= 5) {
printf("%d\n", i);
i++;
goto start;
}

read more about - Control Flow Statements

Storage Class & Function

**1. Memory Organization of a C Program

A C program's memory is divided into several segments:

**1. Code Segment:

**2. Data Segment:

**3. Stack:

**4. Heap:

Used for dynamic memory allocation during runtime (e.g., using malloc() or calloc()).

**2. Storage Classes in C

Storage classes determine the characteristics of a variable such as **scope, **lifetime, and **default value.

op

3. Functions in C

Function Declaration

Functions are blocks of code designed to perform specific tasks. They improve modularity and reusability in a program.
Syntax:

return_type function_name(parameters);

**Function Definition

return_type function_name(parameters) { // function body }

4. Recursion

int factorial(int n) {
if (n == 0) return 1; // Base condition
return n * factorial(n - 1); // Recursive call
}

5. Static and Dynamic Scoping

Static Scooping

Example:

int a = 10;
void main() {
{
int a = 1;
{
int b;
printf("%d", a);
}
}
}

Dynamic Scooping

Example:

int i;
program main() {
i = 10;
call f();
}
procedure f() {
int c = 20;
call g();
}
procedure g() {
print i;
}

read more about - Storage Class and Function