Structure of C Program and First C Program
Structure of C Program
C Language में प्रोग्राम बनाते या लिखते समय हमे उसके “Basic structure” को Follow करना पड़ता है, जिसे सामान्यतः 6 Sections में Divide करते है | अब अगर इन Sections को इनके Right Place से आगे-पीछे लिखे तो program में Error Show करता है ,और हमारा प्रोग्राम Execute या compile नहीं होता, इसीलिए इसके कुछ basic structure है जिसको हमें flow करना पड़ता है | “Basic structure of c” के सभी section को नीचे दर्शाया गया है |
1. Documentation Section
2. Link Section
3. Definition Section
4. Global Declaration Section
5. Main Function Section
6 . User Defined Function Section
Documentation Section
Program को describe करने के लिए Programmer, Documentation Section में Comments लिखता है | Comments को Compiler Ignore कर देता है, उसे Screen पर Print नहीं करता है |
Comments Program को describe करने के काम में आता है | Programmer Comments के अंदर उस Program का Name, Author Name जो उस Program को बना रहा है और दूसरी जानकारियाँ जैसे – Program का date , उसका Objective(About tell what this program do) आदि | ये सब कुछ Documentation Section के अंतर्गत लिखा जाता है |
Link Section
Link Section के अंदर हम अपने Program में Use होने वाले सभी Header Files को Declare करते है | Link Section से हम Compiler को Instruction देते है, कि वो System Libraries से उन Header Files को जिसे हमने Link Section में Declare किया है उसे हमारे इस Program में Link दे |
#include<stdio.h> #include<conio.h> #include<string.h> #include<math.h>
Link Section में इन सब Header Files के आलावा बहुत सारे Header Files भी होते है जिसे हम जरुरत पड़ने पर अपने Program में Link करते है |
Definition Section
C Language में हम जितने Symbolic Constant का Use करते है उसका Definition इस Section में करते है इसलिए इस Section को Definition Section कहते है |
C Language में Program Write करते Time Macros का Definition भी इसी Section में किया जाता है |
#define PI 3.14
Global Declaration Part (GDP)
Global Declarations Section(GDS) के अंदर हम ऐसे Variable को Declare करते है जिनको हम अपने Program में कही भी Use करना चाहते है, ऐसे Variable, Global Variable कहलाते है इन Variables को हम किसी भी Function में कही पर भी Use कर सकते है |
GDS में ही हम ऐसे Function को भी Declare करते है जिनको हम अपने Program में कही भी उपयोग चाहते है और ऐसे Function Global Function कहलाते है |
Main Section
C Language में जब भी हम कोई Program बनाते है तो उस Program में एक main() Function होता ही है | main() Function curly brackets से Start होता है और curly brackets से ही End होता है | main() Function में हम इन Curly Brackets के अंदर ही अपना Statements लिखते है |
main() Function के अंदर हम जो Code लिखते है वो दो Part में होते है एक Declaration Part और दूसरा Execution Part | Declaration Part में हम ऐसे Variable को Declare करते है जिनका Use हमे Execution Part में करना होता है
User Defined Function (Sub Program Section)
इस सेक्शन के अंदर सभी User-Defined Functions को Declare किया जाता है |
Example -:
int sum( int x, int y)
{
return x+y ;
}
C Programming में पहला Program, Hello World को Print करने के लिए हम लिखते है। हम अपने C program को Compile या Run कराने के लिए अलग -अलग IDE’s Use कर सकते है।
#include <stdio.h> int main() { printf("Hello, World"); //single line comment return 0; /* multi line comments /* }
OUTPUT
Hello, World
NOTE: If you have not installed the C compiler in your local machine, first do that to be able to run this program.
Above Program को Run कराने के लिए आपको एक New File बनानी होगी, उस File में Code को Copy-Paste करना होगा और इसे किसी नाम और .c Extension के साथ Save करना होगा या आप इसे चलाने के लिए Turbo C का Use कर सकते हैं।
Program को Successfully Run के बाद, आप उपरोक्त Output को Console पर देखेंगे |