c programming

Structured Programming and Preprocessors

Structured Programming

Structured Programming को Modular Programming के रूप में जाना जाता है| यह एक Programming Paradigm है, जो Readable Code और Reusable Component के साथ Program बनाने की Facilities Provide करता है। सभी Modern Programming Language, Structured Programming को Support करती हैं| लेकिन Programming Language के Syntax की तरह Support के Mechanism, Different होते हैं|

Structured Programming एक Application Program को Module या Autonomous Element के Hierarchy में Divide करने के लिए Encourages करती है। प्रत्येक Element में, Readability और Maintainability में सुधार के लिए Design किए गए Related Logic के Block का use करके Code को और Structure किया जा सकता है|

Modular Programming, में एक Program को Semi-Independent Module में Divide किया जाता है, जिनमें से प्रत्येक को जरूरत पड़ने पर Call किया जाता है। C Language को Structured, Programming Language कहा जाता है, क्योंकि C Language में एक Program को Function, Procedure की मदद से छोटे Logical Functional Module या Structure में Divide किया जा सकता है।

Advantages of Structured Programming

  • यह Top-Down Implementation को प्रोत्साहित करता है, जो Code की Readability और Maintainability दोनों में सुधार करता है|
  • यह Code Reusbility को Increase करता है।
  • यह User Friendly और Easly Understandble, Easy to Learn है।
  • Words और Symbol, English Vocabulary के समान है|
  • Code लिखने के लिए कम समय की आवश्यकता होती है।
  • Programs को Maintain रखना ज्यादा आसान होता है।

Disadvantages of Structured Programming

  • एक High Level Language को Translator द्वारा Machine Language में Translate करना पड़ता है| जोकि Time Consuming Process है|
  • Equivalent Assembly Language Program की तुलना में Translator द्वारा Generated Object Code, Incapable हो सकता है|

Preprocessors

Preprocessors सबसे महत्वपूर्ण और Useful Concept में से एक हैं। Preprocessors, Programmers में Macros को Define करने की Permission देता है| C Programming में Preprocessors को CPP के नाम से भी जाना जाता है।

Preprocessors Compiler को Code Compilation से पहले आवश्यक Processing करने के Instruction Provide करते हैं।’Pre’ का Meaning है – पहले| और ‘Processor’ का Meaning है – कुछ बनाना। यह Compiler का हिस्सा नहीं है,; लेकिन इसे Compilation Process में एक अलग Step के रूप में माना जाता है।

Example – main.c एक C File है, जिसे Preprocessor Process करते हैं| Next Step में यह File Compile हो जाता है, और यह (.obj) Extension के साथ एक Object File बनाता है। उसके बाद (.obj) File को (.exe) File Format में Convert करने के लिए Standard Library Function से जोड़ा जाता है, और फिर इसे Execute किया जाता है।

C Preprocessor Directives

यह Compiler को Compile करने से पहले Source Code को Preprocess करने के लिए Instruction देता है। Preprocessor Directives मुख्य रूप से Command के रूप में use किए जाते हैं। C में, सभी Preprocessor Directives hash/pound(#) Symbol से शुरू होते हैं। Programmer, Program में कहीं भी Preprocessor Directives का use कर सकते हैं। लेकिन Program की शुरुआत में Preprocessor Directives का use करना सबसे अच्छा होता है।

Syntax – #define PI 3.14

Type of Preprocessor Directives

Macros

Macros एक Program में Code के Important Part होते हैं, जिन्हें कुछ नाम दिया जाता है। जब भी Compiler इस नाम को Face करता है, तो Compiler नाम को Code के Actual Piece से बदल देता है। Macros को Define करने के लिए ‘#Define’ Directive का use किया जाता है।

#include <stdio.h>

// macro definition
#define LIMIT 5
int main()
{
for (int i = 0; i < LIMIT; i++) {
printf(“%d \n”,i);
}

return 0;
}

File Inclusion

इस प्रकार का Preprocessor Directive Compiler को Source Code Program में एक File Include करने को Support करता है। Program में Users द्वारा दो प्रकार की File Include की जा सकती हैं-

Header File या Standard Piles

इन Files में printf (), scanf (), आदि जैसे Pre-Defined Function की Definition होती हैं। इन Files को Program में Implement करने के लिए Include किया जाता है। Different Header Files में Different Functions को Declare की जाती है।

Example के लिए Standard I/O Function ‘iostream’ File में हैं ,जबकि String Operation करने वाले Function ‘String’ File में हैं। जहां file_name Include की जाने वाली File का नाम है।

Syntax – #include<file_name >

User-defined files

जब कोई Program बहुत बड़ा हो जाता है, तो इसे छोटी Files में Divide करना और जब भी आवश्यकता हो, उन्हें Include करना एक अच्छा Practice है। इस प्रकार की File User-Defined File हैं। इन File को इस रूप में Include किया जा सकता है|

Syntax – #include”filename

Tags: No tags

Add a Comment

Your email address will not be published. Required fields are marked *