C Programming Detailed Notes (Unit I–V)
Unit I: Basics of C Programming
1.1 Algorithm: An algorithm is a step-by-step procedure to solve a problem. It must be finite,
unambiguous, and effective.
Example: Algorithm to add two numbers: Step1: Start Step2: Input a,b Step3: sum=a+b Step4: Print
sum Step5: Stop
1.2 Structure of C Program:
#include → Header file int main(){ printf("Hello"); return 0;}
Tokens: Smallest units like keywords, identifiers, constants, operators.
Data Types: int, float, char, double. Example: int a=10;
Input/Output:
printf() → output, scanf() → input. Example: scanf("%d", &a;);
Operators: Arithmetic(+,-), Logical(&&), Bitwise(&), sizeof operator.
Unit II: Control Structures
If statement: if(condition){ statements }
Switch: switch(var){ case 1: break; }
Loops:
for(i=0;i<5;i++){} while(condition){} do{}while();
Break & Continue: break exits loop, continue skips iteration.
Unit III: Arrays & Structures
Array: Collection of same type elements. Example: int a[5];
2D Array: int a[2][2];
String: char str[10]; gets(), puts()
Structure: struct student{int id; char name[20];};
Unit IV: Functions
Function: Block of code. Example: int add(int a,int b){return a+b;}
Library Functions: sqrt(), strlen(), malloc()
Recursion: Function calling itself.
Unit V: Pointers
Pointer: Variable storing address. Example: int *p;
Operators: & gives address, * gives value.
Pointer Arithmetic: p++ increments address.
Pointer to Structure: struct student *ptr; ptr->id