C Programming – Module 1
Introduction to C Programming
Flowcharts, Algorithms, Constants,
Variables, Data Types
FLOWCHARTS AND ALGORITHMS
Algorithm
• • Step-by-step procedure to solve a problem
• • Must be clear, unambiguous, and finite
• Example:
• 1. Start
• 2. Read two numbers A, B
• 3. Compute Sum = A + B
• 4. Display Sum
• 5. Stop
Flowchart
• • Graphical representation of algorithm
• • Uses standard symbols:
• ○ Oval – Start/Stop
• ○ Rectangle – Process
• ○ Diamond – Decision
• ○ Parallelogram – Input/Output
• Example: Add two numbers flowchart
OVERVIEW OF C
History and Importance of C
• • Developed by Dennis Ritchie at Bell Labs in
1972
• • Middle-level language (close to machine, but
human-readable)
• • Portable, efficient, widely used in OS,
embedded systems, compilers
Basic Structure of a C Program
• #include <stdio.h>
• int main() {
• printf("Hello, World!\n");
• return 0;
• }
• • Every program has:
• ○ Preprocessor directives
• ○ main() function
• ○ Statements
• ○ Return type
Compiling and Executing
• • Steps:
• 1. Writing source code (.c file)
• 2. Compilation → Object code
• 3. Linking → Executable
• 4. Execution → Output
• • Example using GCC:
• gcc program.c -o program
• ./program
CONSTANTS, VARIABLES & DATA
TYPES
Character Set & Tokens
• • Character Set: Letters, digits, special symbols
• • Tokens: Keywords, Identifiers, Constants,
Operators, Separators
• • Example:
• int age = 25; // int, age, =, 25, ; are tokens
Variables and Data Types
• • Variable: Named memory location
• • Declaration: int a; float b;
• • Data Types:
• ○ int – integers (2, -5)
• ○ float – decimals (3.14)
• ○ char – single characters ('A')
• ○ double – high precision decimals
Constants
• • Constants: Fixed values that cannot be
changed
• • Types:
• ○ Integer constants → 10, -25
• ○ Floating constants → 3.14, -0.98
• ○ Character constants → 'A', '9'
• ○ String constants → "Hello"
• • Symbolic constants: #define PI 3.14159
Const & Volatile
• • const → Makes variable value fixed
• Example: const int x = 10;
• • volatile → Variable value may change
unexpectedly (e.g., hardware registers)
• Example: volatile int flag;
Input/Output in C
• • Input: scanf()
• Example: scanf("%d", &a);
• • Output: printf()
• Example: printf("Sum = %d", sum);
• • Format Specifiers:
• ○ %d – integer
• ○ %f – float
• ○ %c – char
• ○ %s – string
Flowchart Example: Add Two Numbers
Start
Read A, B
Sum = A + B
Print Sum
Stop