🧩 UNIT – I : Introduction to ‘C’ Language
1. Language Fundamentals
History of C Language
- C language was developed by Dennis Ritchie in 1972 at AT&T Bell Laboratories
(USA).
- It was created for writing system software, especially the UNIX operating system.
- C is a middle-level language because it combines the features of high-level and
low-level languages.
- It influenced many modern languages like C++, Java, and Python.
Structure of C Program
A C program generally follows this structure:
#include <stdio.h> // Header File
void main() // Main Function
{
// Variable Declarations
// Statements
}
Main parts:
1. Documentation Section – Comments about the program.
2. Link Section – Includes header files.
3. Definition Section – Defines constants/macros.
4. Global Declaration Section – Declares global variables.
5. Main Function Section – Program execution starts here.
6. User-Defined Functions – Optional reusable functions.
Function as Building Blocks
- C program is divided into functions (small modules).
- Each function performs a specific task.
- The main() function is mandatory — program starts from here.
- Functions help in code reuse, easy debugging, and modular programming.
Character Set
- Alphabets: A–Z, a–z
- Digits: 0–9
- Special Symbols: +, -, *, /, %, =, #, &, etc.
- White spaces: space, tab, newline
C Tokens
- Tokens are the smallest individual units of a C program.
- Types of tokens:
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Operators
6. Special Symbols
Keywords
- Predefined reserved words that have special meaning in C.
- Examples: int, float, char, if, else, for, while, return, switch, break
- Total 32 keywords in C.
Identifiers
- Names given to variables, functions, or arrays.
- Rules:
- Must begin with a letter or underscore (_).
- No spaces or special characters allowed.
- Case-sensitive.
- Example: sum, TotalMarks, _count
Variables
- A named memory location used to store data.
- Must be declared before use.
- Syntax:
int age;
float salary;
- Value of a variable can change during program execution.
Constants
- Fixed values that do not change during program execution.
- Types:
1. Integer constants – e.g., 10, -45
2. Floating constants – e.g., 3.14, -0.55
3. Character constants – e.g., 'A', '5'
4. String constants – e.g., "Hello"
Data Types
int - Integer numbers
float - Decimal numbers
char - Single character
double - Double-precision decimal
void - No value (used in functions)
Comments
- Used to make programs more readable.
- Ignored by compiler.
// Single-line comment
/* Multi-line
comment */
2. Operators
Types of Operators
1. Arithmetic Operators: +, -, *, /, %
2. Relational Operators: <, >, <=, >=, ==, !=
3. Logical Operators: &&, ||, !
4. Assignment Operators: =, +=, -=, *=, /=, %=
5. Increment/Decrement Operators: ++, --
6. Conditional Operator: ?:
7. Bitwise Operators: &, |, ^, ~, <<, >>
8. Special Operators: sizeof(), comma (,), pointer (*, &)
Precedence and Associativity
- Defines order of evaluation of operators.
Example: *, /, % have higher precedence than +, -
- Associativity decides direction (Left-to-right or Right-to-left).
Expressions
- Combination of variables, constants, and operators.
Example: total = a + b * c;
Statements
- Instructions written in a program that perform an action.
Example: printf("Hello");
Types of Statements
1. Expression statements
2. Compound statements
3. Control statements
4. Jump statements
3. Input/Output Functions
Console-based I/O Functions
- Used to take input and show output using keyboard and screen.
Built-in I/O Functions
printf() - Output to screen
scanf() - Input from user
getch() - Waits for a key press (no echo)
getche() - Waits for a key press (echoes character)
putchar() - Prints a single character
4. Header Files & Preprocessor Directives
Concept of Header Files
- Header files contain predefined functions and macros.
Example:
#include <stdio.h> → for input/output
#include <math.h> → for math functions
Preprocessor Directives
- Commands that are processed before compilation.
#include → Includes header file.
#define → Defines constant or macro.
⚙️ UNIT – II : Control Structures
1. Decision-Making Statements
if – Executes a block if condition is true.
if-else – Executes one block if true, another if false.
Nested if-else – if inside another if.
switch – Selects one case from many options (uses case and break).
2. Iteration (Looping) Statements
while – Condition checked before loop.
do-while – Condition checked after loop (runs at least once).
for – Compact form with initialization, condition, increment.
3. Jumping Statements
goto – Transfers control to a labeled statement.
return – Exits from a function.
break – Exits from loop or switch.
continue – Skips remaining statements of current iteration.
4. Arrays in C
Definition: Array is a collection of similar data types stored in contiguous memory
locations.
Declaration: int marks[5];
Initialization: int marks[5] = {90, 80, 70, 60, 50};
Types of Arrays:
1. Single-Dimensional Array – Linear data storage (int arr[5];)
2. Multi-Dimensional Array – Data in matrix form (int matrix[3][3];)