Table of Contents

Structure of a C Program in Hindi – C Program की संरचना

Get Your Professional Business Website

C एक general-purpose programming language है जिसका उपयोग system software, embedded systems और विभिन्न applications बनाने के लिए किया जाता है। C में program लिखने के लिए code को एक व्यवस्थित structure में रखा जाता है।

Structure of a C Program का अर्थ है program के अलग-अलग parts को सही तरीके से organize करना। एक सामान्य C program में preprocessor directives, global declarations, main() function, statements और जरूरत के अनुसार user-defined functions हो सकते हैं।

हर C program में सभी parts का होना जरूरी नहीं है। Program की आवश्यकता के अनुसार इसकी structure छोटी या बड़ी हो सकती है।

Basic Structure of C Program in Hindi

नीचे एक सामान्य C program की structure दी गई है। इसमें comments, header file, main() function, variable declaration, executable statements और return statement शामिल हैं।

/* Documentation Section */

#include 

int main(void)
{
    // Variable Declaration
    int a = 10;
    int b = 20;
    int sum;

    // Executable Statements
    sum = a + b;

    printf("Sum = %d\n", sum);

    return 0;
}

इस program में stdio.h header file को include किया गया है। main() function के अंदर variables declare किए गए हैं, दो numbers का sum calculate किया गया है और printf() function से result display किया गया है।

Output:

Sum = 30

यह एक सामान्य example है। C language में program की structure इसी exact format तक सीमित नहीं है। जरूरत के अनुसार functions, global declarations और दूसरे components भी जोड़े जा सकते हैं।

Parts of a C Program in Hindi

एक सामान्य C program के मुख्य parts नीचे दिए गए हैं।

1. Documentation Section

Documentation section में comments लिखे जाते हैं। इनका उपयोग program का purpose और code के काम को समझाने के लिए किया जाता है। Comments को compiler executable instructions की तरह execute नहीं करता।

/* Program to add two numbers */

C में comments दो तरीकों से लिखे जा सकते हैं।

  • // का उपयोग single-line comment के लिए होता है।
  • /* ... */ का उपयोग multi-line comment के लिए होता है।

Comments लिखना जरूरी नहीं है, लेकिन इनसे code को पढ़ना और समझना आसान हो सकता है।

2. Preprocessor Directives

Preprocessor directives का उपयोग compilation से पहले preprocessing instructions देने के लिए किया जाता है। Header file को include करने के लिए #include directive का इस्तेमाल किया जाता है।

#include 
  • stdio.h standard input और output functions की declarations उपलब्ध कराती है।
  • printf() जैसे functions का उपयोग करने पर सामान्यतः इस header file को include किया जाता है।
  • Preprocessor directives की शुरुआत # से होती है।

3. Global Declarations

Global declarations में variables, function prototypes और अन्य declarations लिखे जा सकते हैं। ये आमतौर पर सभी functions के बाहर लिखे जाते हैं।

#include 

int total = 100;

void display(void);

int main(void)
{
    display();
    return 0;
}

void display(void)
{
    printf("%d\n", total);
}

इस example में total एक file-scope variable है और display() का function prototype main() से पहले दिया गया है। Global declarations हर program में जरूरी नहीं होते।

4. main() Function

Hosted C program में main() function entry point होता है। Program का execution इसी function से शुरू होता है।

int main(void)
{
    printf("Hello World\n");
    return 0;
}
  • int main() function का return type है।
  • void का अर्थ है कि function कोई arguments नहीं लेता।
  • Curly braces { } function body को दर्शाती हैं।
  • Function के अंदर executable statements लिखे जाते हैं।

5. Variable Declarations

Variables का उपयोग program में data store करने के लिए किया जाता है। Variable declaration में उसका data type और नाम बताया जाता है। जरूरत के अनुसार declaration के साथ initial value भी दी जा सकती है।

int age = 20;
float marks = 85.5f;
char grade = 'A';
  • int का उपयोग integer values के लिए किया जाता है।
  • float का उपयोग floating-point values के लिए किया जाता है।
  • char का उपयोग character values के लिए किया जाता है।

इन declarations को main() function के अंदर local variables के रूप में या उचित scope में दूसरे स्थानों पर लिखा जा सकता है।

6. Executable Statements

Executable statements program के execution के दौरान operations perform करते हैं। इनमें calculations, assignments, conditions, loops और function calls शामिल हो सकते हैं।

int a = 10;
int b = 20;
int sum;

sum = a + b;
printf("%d\n", sum);

इस example में sum = a + b; दो numbers को add करता है और printf() result को screen पर display करता है।

7. User-Defined Functions

Programmer अपनी जरूरत के अनुसार functions बना सकता है। User-defined functions program को छोटे और reusable parts में divide करने में मदद करते हैं।

int add(int a, int b)
{
    return a + b;
}

इस example में add() function दो integer arguments लेता है और उनका sum return करता है। Function का prototype जरूरत के अनुसार पहले declare किया जा सकता है।

हर C program में user-defined function होना जरूरी नहीं है। छोटे programs में केवल main() function भी पर्याप्त हो सकता है।

8. return Statement

return statement function का execution समाप्त करता है और जरूरत के अनुसार value वापस देता है।

int main(void)
{
    return 0;
}

Hosted C environment में main() से return 0; करने का सामान्य अर्थ है कि program successful termination status के साथ समाप्त हुआ।

Example of a C Program in Hindi

नीचे एक simple C program दिया गया है जो screen पर Hello World display करता है।

#include 

int main(void)
{
    printf("Hello World\n");
    return 0;
}

Output:

Hello World

इस program में:

  • #include standard input और output functions की declarations उपलब्ध कराता है।
  • int main(void) program का entry point define करता है।
  • printf() screen पर Hello World display करता है।
  • \n output के बाद नई line पर जाने के लिए उपयोग होता है।
  • return 0; successful termination status दर्शाता है।

Execution of a C Program in Hindi

C program को run करने से पहले सामान्यतः source code को compile करके executable बनाया जाता है। इसके मुख्य steps नीचे दिए गए हैं।

1. Writing Source Code

सबसे पहले programmer C language में code लिखता है और उसे .c extension वाली file में save करता है, जैसे program.c।

2. Preprocessing

Preprocessor #include और #define जैसी directives को process करता है। इसमें header files और macros से संबंधित काम किया जाता है।

3. Compilation

Compiler source code को translate करता है और syntax सहित अन्य compile-time errors की जाँच करता है। Toolchain के अनुसार object file या intermediate output तैयार हो सकता है।

4. Linking

Linker object code और जरूरी libraries को जोड़कर executable बनाता है। कुछ development tools में compilation और linking अलग-अलग steps के रूप में दिखाई देते हैं।

5. Execution

Executable file run करने पर program execute होता है। Program के statements के अनुसार output मिलता है।

इस तरह source code लिखने से लेकर executable run करने तक की प्रक्रिया पूरी होती है।

FAQs

Structure of a C Program code को organize करने का तरीका है। इसमें जरूरत के अनुसार preprocessor directives, declarations, main() function, executable statements और user-defined functions शामिल हो सकते हैं।
एक सामान्य C program में documentation comments, preprocessor directives, declarations, main() function, executable statements और जरूरत के अनुसार user-defined functions हो सकते हैं।
Hosted C program में main() function entry point होता है। Program का execution इसी function से शुरू होता है।
#include standard input और output functions की declarations उपलब्ध कराता है। इसका उपयोग printf() जैसे functions के लिए किया जाता है।
नहीं। Program की जरूरत के अनुसार structure बदल सकती है। Comments, global variables और user-defined functions हर program में होना जरूरी नहीं है।
Hosted C environment में main() से return 0; करने का सामान्य अर्थ है कि program successful termination status के साथ समाप्त हुआ।
पहले source code को compiler से compile किया जाता है और फिर बने executable को run किया जाता है। GCC में gcc program.c -o program जैसी command का उपयोग किया जा सकता है।
Arpit

✍️ Arpit

Post-graduated | Web Developer

•