Notes in Hindi

What is a Compiler in C Language in Hindi

/ BCA / Programming with C and CPP

What is Compiler in C Language in Hindi

What is a Compiler in C Language in Hindi

Compiler एक ऐसा software होता है जो C Language में लिखे गए पूरे program को एक साथ पढ़ता है और उसे machine language (यानि 0 और 1 की भाषा) में convert कर देता है ताकि computer उसे समझ कर execute कर सके। C Language एक high-level language है, जिसे इंसान आसानी से पढ़ और समझ सकता है, लेकिन computer सिर्फ machine language समझता है। इसी gap को bridge करने का काम compiler करता है।

Why Compiler is Needed in C Language

  • C Language में लिखा हुआ code, computer directly नहीं समझ सकता।
  • Compiler इस code को translate करता है machine language में।
  • Compiler पूरे program को एक साथ check करता है और errors को बताता है।
  • Compile होने के बाद output generate होता है जिसे हम run करके result देख सकते हैं।

Example

मान लीजिए हमने एक simple C Program लिखा:

#include <stdio.h> int main() { printf("Hello, World!"); return 0; }

इस code को computer तभी समझेगा जब यह compile होकर machine code में बदल जाए। यही काम करता है compiler।

Role of Compiler in Program Execution in Hindi

Compiler का मुख्य कार्य source code को executable file में बदलना होता है। जब हम किसी C Program को लिखते हैं, तो वह सिर्फ इंसानों के पढ़ने योग्य होता है। लेकिन computer उसे तब तक execute नहीं कर सकता जब तक वह compiled न हो। Compiler का role step-by-step इस प्रकार है:

Main Functions of Compiler

  • Source Code को scan करना और errors detect करना।
  • Syntax को check करना, अगर कोई गलती हो तो उसे report करना।
  • Source Code को intermediate form या assembly में convert करना।
  • Code को optimize करना ताकि program तेजी से चले।
  • Machine code (binary code) generate करना जो computer run कर सके।

Program Execution Process

  • Step 1: User C code लिखता है।
  • Step 2: Compiler उसे machine language में बदलता है।
  • Step 3: Executable file (जैसे a.exe) बनती है।
  • Step 4: Operating System उस executable को run करता है।

Difference between Compiler and Interpreter in Hindi

Compiler और Interpreter दोनों का काम high-level language को machine language में बदलना होता है, लेकिन इन दोनों के काम करने के तरीके में काफी अंतर होता है।

Feature Compiler Interpreter
Translation का तरीका पूरा program एक बार में translate होता है। Program line-by-line translate होता है।
Execution Speed तेजी से चलता है क्योंकि पूरा code पहले से compiled होता है। धीमा चलता है क्योंकि हर line को run-time पर interpret करता है।
Error Detection सभी errors एक साथ बताता है compile time पर। एक error पर ही रुक जाता है, line-by-line बताता है।
Output Executable file बनती है। Executable file नहीं बनती।
उदाहरण C, C++ Python, JavaScript

Phases of Compilation in C Language in Hindi

जब हम C Language में कोई program लिखते हैं और उसे compile करते हैं, तो compiler उसे कई चरणों (phases) में process करता है। हर चरण का एक अलग काम होता है और सभी मिलकर final machine code generate करते हैं। नीचे compilation के मुख्य phases विस्तार से दिए गए हैं:

1. Lexical Analysis

  • यह पहला चरण होता है।
  • Source Code को tokens में तोड़ता है जैसे keywords, identifiers, operators आदि।
  • Whitespace और comments को हटा देता है।

2. Syntax Analysis (Parsing)

  • इस phase में यह देखा जाता है कि program का structure सही है या नहीं।
  • Compiler इस दौरान syntax tree बनाता है।
  • यदि कोई grammar mistake हो तो error show करता है।

3. Semantic Analysis

  • यह check करता है कि variables और types का use सही है या नहीं।
  • Type mismatch जैसे errors यहां detect होते हैं।

4. Intermediate Code Generation

  • यह एक temporary code generate करता है जो machine independent होता है।
  • इससे optimization करना आसान होता है।

5. Code Optimization

  • यह phase code को बेहतर बनाता है ताकि output जल्दी और कम resources में मिले।
  • Redundant या useless instructions को हटाता है।

6. Code Generation

  • यहां final machine code generate होता है।
  • Target machine architecture के अनुसार binary code बनता है।

7. Code Linking and Assembly

  • Program में जिन external files या functions का use हुआ है, उन्हें link किया जाता है।
  • Final executable file बनती है जैसे a.exe (Windows) या a.out (Linux)।

Summary Table of Compilation Phases

Phase Work
Lexical Analysis Tokens बनाना
Syntax Analysis Structure check करना
Semantic Analysis Meaning check करना
Intermediate Code Middle form में code generate करना
Optimization Code को fast और efficient बनाना
Code Generation Machine code बनाना
Linking Final executable बनाना

इन सभी phases के साथ compiler C Program को सही तरीके से machine code में बदल कर computer को समझने योग्य बना देता है।

FAQs

Compiler एक software होता है जो C Language में लिखे गए पूरे program को एक साथ पढ़कर उसे machine language (0 और 1) में बदल देता है ताकि computer उसे समझ सके और execute कर सके।
Compiler source code को पहले machine code में बदलता है और फिर उसे executable file में convert करता है। इसके बिना program run नहीं हो सकता।
Compiler पूरा program एक साथ translate करता है जबकि Interpreter line-by-line करता है। Compiler executable file बनाता है, Interpreter नहीं बनाता।
Compilation के मुख्यतः 7 phases होते हैं: Lexical Analysis, Syntax Analysis, Semantic Analysis, Intermediate Code Generation, Code Optimization, Code Generation और Linking।
सबसे प्रसिद्ध C Compiler software हैं: GCC (GNU Compiler Collection), Turbo C, और Clang। इनमें से GCC सबसे अधिक प्रयोग किया जाता है।
Machine code वह binary format होता है (0 और 1 में) जो computer सीधे पढ़ और समझ सकता है। Compiler C code को इसी machine code में convert करता है।

Please Give Us Feedback