Lesson 1 — Beginner
C Programming kya hai — Introduction
C ek powerful general-purpose language hai jo 1972 mein bani aur aaj bhi duniya ke sabse important software usi mein bane hain. Is lesson mein hum samjhenge ki C hota kya hai, kyun itni important hai, aur tumhara pehla C program kaise compile aur chalta hai.
C programming kya hai
WHAT
C ek general-purpose, mid-level programming language hai jo 1972 mein Dennis Ritchie ne Bell Labs mein banayi. Ye high-level jaisi padhi jaati hai (English jaisa syntax) aur low-level jaisi kaam karti hai (memory aur hardware ke paas access).
WHEN
Jab bhi tez, resource-efficient program chahiye — OS, embedded systems, drivers, compilers, databases — C sabse pehle choice hai. Interviews aur college exams mein bhi C hi base language mana jaata hai.
WHERE
Linux kernel pura C mein hai, Python ka interpreter bhi C mein likha gaya hai, har router aur smart device ke andar C code chalta hai. Tumhara phone bhi C se bane software par hi chalta hai.
C ka ek line ka funda: syntax simple, power full. Itni chhoti language mein tum memory tak direct pahunch sakte ho — isi liye 50 saal baad bhi C industry mein raj kar rahi hai.
C ki history — CPL se C tak
1967 : BCPL (Basic Combined Programming Language) — Martin Richards
1969 : B language — Ken Thompson ne Unix ke liye banayi
1972 : C language — Dennis Ritchie ne B se develop ki
1973 : Unix OS C mein rewrite hua (pehle assembly mein tha)
1978 : "The C Programming Language" book (K&R) — standard ban gayi
1989 : ANSI C (C89) — official standard
1999 : C99 — inline functions, variable declarations
2011 : C11 — threads, atomics (aaj ka modern C)
Dhyan do: Unix aur C ek doosre ke saath bade. Unix chalane ke liye C bani, aur C ko test karne ke liye Unix kaam aaya. Aaj Linux, macOS sab Unix-based hain — isliye C aaj bhi zinda hai.
C kyun seekhein — features
- Speed: Compiled language hai — direct machine code banti hai. Python se kaafi tez, isliye embedded aur real-time systems mein C hi chunta hai.
- Portability: Ek baar likha, gcc se dusre machine pe compile kar do — chal jaayega. Write once, compile anywhere.
- Memory access: Pointers se memory ko directly control kar sakte ho — ye C ki sabse badi taakat hai.
- Foundation: C++, Java, Python, JavaScript — sabka syntax aur concept C se aaya hai. C seekh lo, baaki languages 70% apni lagengi.
- Rich library: math.h, string.h, stdlib.h — har kaam ke liye ready functions library mein.
- Modular: Functions mein tod kar bade se bada project manageable hota hai.
Practical truth: DSA practice C/C++ mein hi hoti hai, competitive coding ka base bhi yahi hai, aur placements mein pehla coding test aksar C ya C++ mein hota hai.
Tumhara pehla C program
#include <stdio.h>
int main() {
printf("Hello, DSWallah!\n");
return 0;
}
Output:
Hello, DSWallah!
- #include <stdio.h> — preprocessor ko bolta hai ki printf ka declaration stdio.h se le aao.
- int main() — program yahin se chalta hai (entry point). Har C program mein exactly ek main hota hai.
- printf(...) — screen pe text chhapta hai. \n ka matlab hai new line.
- return 0; — operating system ko batata hai ki program safaltapoorvak chala (0 = success).
gcc hello.c -o hello # compile (GCC compiler)
./hello # run (Linux/Mac)
hello.exe # run (Windows)
# warnings ke saath strict compile:
gcc -Wall hello.c -o hello
C ka compilation process (4 stages)
Source (hello.c)
↓ 1. PREPROCESSOR — #include, #define expand, comments hatao
hello.i (expanded source)
↓ 2. COMPILER — C code → assembly code (syntax errors yahin)
hello.s (assembly)
↓ 3. ASSEMBLER — assembly → machine code (object file)
hello.o (object)
↓ 4. LINKER — library functions (printf) join + main jodo
hello (executable)
Ek command mein sab: gcc hello.c -o hello
Ye 4 stages har exam mein poochhi jaati hain: preprocessor → compiler → assembler → linker. Linker ka kaam samjho — tumne printf nahi likha, wo stdio library mein pada hai; linker use tumhare program se jodta hai.
Exercise
Question: C language kisne banayi? (poora naam, space se likho)
Question: C language kis saal bani? Sirf number daalo.
Question: C program ka entry point (shuruaat wala function) ka naam kya hai?
Question: Compilation ki pehli stage ka naam kya hai? (preprocessor / compiler / linker)
Common mistakes
- C ko high-level language samajhna: C mid-level hai — high-level jaisa syntax aur low-level jaisa memory access. Sirf high-level bolna aadha answer hai.
- #include ko function call samajhna: #include ek preprocessor directive hai jo poora header file paste kar deta hai — function call nahi hoti, koi code runtime pe nahi chalta.
- Linker aur compiler mein confusion: Compiler code ko assembly mein badalta hai, linker object files aur libraries ko jod kar final executable banata hai. Order yaad rakho.
Ghar pe roti banne ka poora process compilation jaisa hai — har stage ek kaam karti hai, aur koi stage chhodi toh roti plate pe nahi aayegi:
Aata (source) → preprocessor: chaan-na, ready karna
Belna (compile) → code ko shape dena (assembly)
Secna (assemble)→ machine code banao
Serve (link) → plate pe jodo (libraries)
Roti (output) → program chal gaya!- TCS NQT: "Who developed C?" — Dennis Ritchie, 1972, Bell Labs.
- College exam: Hello World program likhwana + header file ka kaam poochha jaata hai.
- GATE: 4 stages of compilation ka order — preprocessor → compiler → assembler → linker.
- Trap: "#include ek function hai" — galat, wo preprocessor directive hai.
C ka introduction clear. Agla lesson — Variables & Data Types — mein dekhenge data store kaise karte hain aur kitne type ke variables hote hain.