You are here: Home / Hindi Web /Topics / Chapter 8 - How to write first C Program

Chapter 8 - How to write first C Program

Filed under: C Programming Tutorials on 2022-03-01 17:15:11

C में कोई भी program create करने के 4 steps होते है। ये steps एक निश्चित क्रम में होते है और इनमें से हर step का  अपना महत्व होता है।

1. सबसे पहले आप एक program को लिखते है। इसे program development life cycle का editing part कहते है। ये program human readable format में होता है। 

2. इसके बाद आप program को compile करते हैं। ये development life cycle का second step होता है। इस part में सभी errors को remove करके program को binary format में convert किया जाता है ताकि computer इसे process कर सके। 

3. इसके बाद linking process आती है। इस process में program को जरूरी libraries के साथ link किया जाता है। जैसे की आपको पता है की C का basic program भी बिना libraries को include किये नहीं execute हो सकता है। Libraries C program को execute होने के लिए environment provide करती है।

4. इसके बाद executable file produce कर दी जाती है। जिसे आप जितनी बार चाहे execute कर सकते है। Editing process का output .c source file होती है। Compiling process का input source .c file होती है और output .obj file होती है। Linking process का input .obj file होती है और output .exe file होती है। 

Structure of C Program

Your First C Program

/* Header file declaration */
#include

/* Main function declaration */

int main()
{
    /* Printing message to screen */
    printf(“Hello Readers!”); 
 
   /* returning */
    return 0;

}

Hello Readers! 

सबसे पहली line में header file को program में include किया गया है। ये एक standard input/output header file होती है जो program में input और output को handle करती है।

इन्हें program में include करने के लिए preprocessor directives का प्रयोग किया जाता है। इसके बाद main() function को start किया गया है। Main function से ही program का execution start होता है। इसी function में सभी instructions लिखे जाते है।

Main function का start और end curly brackets के द्वारा show किया जाता है। इन curly brackets के भीतर के सभी instructions execute किये जाते है।

Main function को int type के साथ define किया गया है। ये एक standard है। Main function को हमेशा एक integer value return करनी होती है। यदि आप program में main() function से कोई value return नहीं करते है तो program के आखिर में return 0 statement लिखते है।

Main function में आप arguments भी pass कर सकते है जिन्हें command line arguments कहा जाता है। इनके बारे में अधिक जानकारी के लिए C Language Command Line Arguments in Hindi tutorial पढ़े।

Commenting 

एक comment आपके program में वो text होता है जिसे compiler ignore कर देता है। ये text बाकी statements की तरह execute नहीं होता है। Comments program में किसी statement को या फिर program को define करने के लिए use किये जाते है।

/* Your comment will be here */ 

C language में comments define करने के लिए forward slash (/) और asterisk (*) का प्रयोग किया जाता है।

#include

int main() /* Main function starts from here*/
{
   printf(“Hello World!”);  /* This statement will print Hello World message */

   return 0;

ऊपर दिए गए program में comments के माध्यम से program और दूसरे statements के बारे में explanation दी गयी है।

Hello World! 
About Author:
M
Madhu     View Profile
Trust everyone but don't trust blindly