Notes in Hindi

Basic structure of a C program in Hindi

/ BCA / Programming with C and CPP

Basic Structure of a C Program in Hindi

Basic structure of a C program in Hindi

Introduction

C language एक बहुत ही popular और powerful programming language है, जिसे beginners के लिए बहुत ही उपयुक्त माना जाता है। किसी भी C program को लिखते समय एक निश्चित structure follow किया जाता है। इस structure को समझना हर नए programmer के लिए बहुत जरूरी होता है क्योंकि अगर structure गलत होगा, तो program compile नहीं होगा।

Parts of a C Program

C program के structure में कई parts होते हैं, जो मिलकर एक complete C program बनाते हैं। नीचे हम सभी parts को विस्तार से समझेंगे:

  • 1. Documentation Section: यह optional होता है। इसमें हम comments लिखते हैं जो program के बारे में जानकारी देते हैं। ये programmer के लिए helpful होते हैं लेकिन compiler इन्हें ignore कर देता है।
  • 2. Preprocessor Section: इस section में हम header files include करते हैं जैसे #include<stdio.h>। ये files पहले से defined functions और macros provide करती हैं।
  • 3. Definition Section: इस part में हम constants define कर सकते हैं जैसे #define PI 3.14। यह भी preprocessor directive का हिस्सा होता है।
  • 4. Global Declaration Section: इसमें हम ऐसे variables और functions को declare करते हैं जिनका use पूरे program में होगा।
  • 5. main() Function: यह program का entry point होता है। कोई भी C program main() function से शुरू होता है। इसके अंदर program का actual code लिखा जाता है।
  • 6. Subprogram Section: इसमें हम अलग-अलग user-defined functions को define करते हैं। ये modular programming में help करते हैं।

Header files and preprocessor directives in C structure in Hindi

What are Header Files?

Header files वे files होती हैं जिनमें पहले से लिखे हुए functions और macros होते हैं। जब हम C program लिखते हैं तो हमें कई बार उन functions की जरूरत होती है जो standard library में पहले से available होते हैं, जैसे printf(), scanf() आदि। इन्हें use करने के लिए हमें header files को include करना होता है।

Commonly Used Header Files

Header File Use
<stdio.h> Input/Output functions जैसे printf(), scanf() के लिए
<conio.h> Console input/output functions जैसे getch(), clrscr() के लिए
<math.h> Mathematical functions जैसे sqrt(), pow() के लिए
<string.h> String handling functions जैसे strcpy(), strlen() के लिए

What are Preprocessor Directives?

Preprocessor directives वो instructions होती हैं जो compiler के actual compilation शुरू होने से पहले process होती हैं। ये # symbol से शुरू होती हैं। जैसे:

#include<stdio.h> // यह एक header file को include करता है
#define PI 3.14 // यह एक constant define करता है

Preprocessor directives का काम है - header files को जोड़ना, macros को define करना, conditional compilation करना, आदि।

Role of main() function in C program structure in Hindi

Importance of main() Function

C program का सबसे important हिस्सा main() function होता है। यह program का entry point होता है। जब आप C program run करते हैं, तो सबसे पहले main() function ही execute होता है। अगर program में main() function नहीं है, तो compiler error देगा।

Syntax of main() Function

int main() {
    // Code यहाँ लिखा जाता है
    return 0;
}
  • int: इसका मतलब है कि main() function एक integer value return करेगा। सामान्यतः यह 0 return करता है जो बताता है कि program successfully run हुआ।
  • return 0: इसका अर्थ है कि program ने कोई error नहीं दी और successful तरीके से execute हुआ।

Alternate Syntax

void main() {
    // Code यहाँ लिखा जाता है
}

लेकिन ध्यान दें कि int main() को standard माना जाता है और वही use करना बेहतर होता है।

Syntax rules followed in C program structure in Hindi

What is Syntax?

Syntax का मतलब होता है किसी भाषा के लिखने का नियम। जैसे हिंदी में वाक्य बनाने के नियम होते हैं, वैसे ही C language में भी code लिखने के नियम होते हैं। अगर syntax गलत होगा, तो compiler error देगा।

Important Syntax Rules in C

  • 1. हर statement के बाद semicolon (;) लगाना अनिवार्य है।
    जैसे: printf("Hello");
  • 2. curly braces { } का सही से use करना जरूरी है।
    ये blocks को define करते हैं। हर opening brace का एक closing brace होना चाहिए।
  • 3. variables को use करने से पहले declare करना जरूरी है।
    जैसे: int a;
  • 4. C language case-sensitive होती है।
    main और Main अलग-अलग माने जाएंगे।
  • 5. C program top to bottom execute होता है।
    इसलिए functions को पहले declare करना जरूरी होता है अगर उन्हें main() से पहले define नहीं किया गया हो।

Example of a Valid C Program

#include<stdio.h>

int main() {
    int a = 10;
    printf("Value of a is: %d", a);
    return 0;
}

ऊपर दिए गए program में सभी syntax rules follow किए गए हैं। इसलिए यह successfully compile और run होगा।

Common Syntax Errors

  • missing semicolon: statement के अंत में ; न लगाने से error आता है।
  • undeclared variable: अगर variable declare नहीं किया गया और use किया गया तो error आता है।
  • mismatched braces: अगर { और } का pair ठीक से नहीं है, तो भी compiler error देगा।

C language में syntax का पालन करना बहुत जरूरी होता है। इससे ना केवल आपका program error-free बनता है, बल्कि अच्छे programmers की पहचान भी होती है।

FAQs

C प्रोग्राम की बेसिक संरचना में documentation section, preprocessor directives, global declarations, main() function और user-defined functions शामिल होते हैं। हर part का एक specific कार्य होता है।
Header files का उपयोग पहले से बने functions जैसे printf(), scanf() को program में use करने के लिए किया जाता है। ये files predefined code को access करने की सुविधा देती हैं।
main() function किसी भी C प्रोग्राम का entry point होता है। program की execution यहीं से शुरू होती है और यही function पूरे program को control करता है।
printf() function के लिए #include<stdio.h> header file जरूरी होती है क्योंकि यह standard input/output operations को support करती है।
Preprocessor directives ऐसी instructions होती हैं जो compilation से पहले process होती हैं। जैसे #include, #define आदि। ये program की efficiency और modularity को बढ़ाते हैं।
C में हर statement के बाद semicolon लगाना जरूरी होता है, variables को declare करना अनिवार्य होता है, और blocks के लिए { } braces का सही उपयोग करना जरूरी होता है। साथ ही, C एक case-sensitive language है।

Please Give Us Feedback