What is Basic Structure of C in Hindi
C में Programming सीखने के लिए उसके Basic Structure की जानकारी होना आवश्यक है जो Program को पढ़ने, समझने और सुधारने में सहायक होते है
बिना सही Structure के Program में Compliation और Execution के दौरान समस्या का सामना करना पड़ सकता है
अतः नीचे C Program की Basic Structure को 6 भागों मे बांटा गया है।
1) Documentation
2) Preprocessor(Link Section)
3) Definition
4) Global Declaration
5) Main () Function
6) Sub Programs
Documentation(Document Section)
Document Section में Comment Lines का एक Set शामिल रहता है जिसमें कुछ जानकारी जैसे Program का Description, Programmer का नाम Program के निर्माण का Date, Time और अन्य Details रहते है
Documentation को निम्न प्रकार से Comments में प्रदर्शित कर सकते हैं
Single Line Comment
// This is a single-line comment in C
Multiple Line Comment
/*
This is a
multi-line comment
*/
Example
//Write a Program to Add two numbers
/*
Programmer's name:- God is Love
File name :- learn.c
Date :- 12/01/24
*/
Comments में जो भी लिखा जाता है वह Program की Functionality को प्रभावित नही करती यह Programmers के लिए विवरण या Notes की भांति कार्य करता है
Preprocessor (Link Section)
Link Section Compiler को System Libraries के Function को Link करने का निर्देश देती है इसके लिए #Include directive का use करते है
Example
#Include<stdio.h>
यहां पर stdio.h(standard input output header file है) मतलब System Libraries में ऐसे Functions है जिसे हम अपने Program में Use करना चाहते है जैसे stdio.h में बहुत सारे function होते
है उनमें से एक है printf function यदि
हम इस function का Use करना चाहते है तो हमे <stdio.h> Header File को Program मे Include करना पड़ेगा इसके लिए हमे #include<stdio.h> को Link Section में लिखना होता है ताकि Complier printf की Definiation को समझने के लिए stdio.h Header File का Use कर सकें
Definiation Section
Definition Section में #define directive का Use करके सारे Symbolic Constants को Define किया जाता है
इस भाग मे किसी Value के लिए Name Define किया जाता है ताकि हम पूरे Program में उस Name का प्रयोग कर Value को प्राप्त कर सकें
Example
#define Max = 356
#define Pie = 3.14
ऊपर Max के लिए 356 और Pi के लिए 3.14 Define किया गया है हम आगे Program मे Max और Pi Name का प्रयोग करके उसके Value को Access कर सकते है
Global Declaration
कुछ ऐसे Variables होते है जिनका प्रयोग एक से अधिक Functions में किए जाते है ऐसे Variables को Global Variables कहते हैं
इन Global Variables को Global Declaration Section में Declare किया जाता है जो सभी Functions से बाहर होते है
इन Section में सभी User Defined Functions को भी Declare किया जाता है
C मे दो प्रकार के Variable Declaration किए जाते है
1) Local variable declaration:
ये Variables main function के अंदर Declare किए जाते है
2) Global variable declaration: ये Variables main function के बाहर Declare किए जाते है
Example
int x; //Global variable
main()
{
int a; // Local Variable
}
Local Variable Function के अंदर Declare होता है जो केवल उसी Function में Use होता है जैसे int a main() के अंदर Declare हुआ है
जबकि Global Variable Function के बाहर Declare होता है जिसे दूसरे Function भी Use कर सकते है जैसे int x , main() के बाहर Declare हुआ है
प्रत्येक C Program में एक main() अवश्य होता है यह पहला Function है जिसे Computer द्वारा Execute किया जाता है main () Program के शुरुवाती भाग मे होता है यह C की Library मे उपस्थित अन्य Function के समान ही होता है () Parenthesis का प्रयोग Parameter Pass करने के लिए होता है
इस Section के दो भाग होते है
a) Declaration
Declaration भाग मे वे सभी Variables Declare किए जाते है जिनका Executable Part में Use किए जाते है
b) Executable Part
Executable Part मे कम से कम एक Statement होते है
Example
main()
{
int x; //Declaration part
x = x+5; //Executable part
}
Sub Programs
यदि Program एक Multifunction Program है तब Sub Program सभी User Defined Functions को रखता है इन User Defined Functions को main() में Call किया जाता है
Example
int add(int x int y)
{
return x+y;
}
>
Basic Structure of C programming
// Documentation
/*
File name :- myprogram.c
Author name:- God is Love
Date:- 11/01/2024
Purpose:-
Write a program to display message.
*/
//Link Section
#include<stdio.h>
//Definition Section
#define pi = 3.14
//Global declaration
int x = 10;
void showMessage();
//Main() Function Section
int main()
{
printf("Hello, World!\n");
showMessage();
return 0;
}
//Subprogram Section
void showMessage()
{
printf("Here in subprogram section user-defined function is defined !\n");
}
Output:
Hello, World!
Here in subprogram section user-defined function is defined !
Explanation :-
ऊपर के Program की Basic Structure को एक एक करके निम्न प्रकार से समझते हैं
1) Documentation:-
यह Documentation भाग है जिसमे Comment होते है जिसके अन्दर Program और Programmer संबन्धित जानकारी होती है
/*
File name :- myprogram.c
Author name:- God is Love
Date:- 11/01/2024
Purpose:-
Write a program to display message.
*/
2) Link Section:-
इस भाग में Header File होते है जो C Language के System Libraries में होते है इस Header File के अंदर Defined Function का Use Program में किया जाता है
#include <stdio.h>
3)Definiation Section:-
यह Definiation Section है यहां Defined किए गए Constant pi की Value को आगे Program Code में Use किया जा सकता है
#define pi = 3.14
4)Global declaration:-
यह Global Declaration Section है जिसमे आप कोई भी Variable या Function Declare करके उसे Program में कहीं भी Use कर सकते हैं जैसे हमने नीचे एक Variable x और एक Function displayMessage() Declare किया है
int x = 10;
void showMessage();
5) Main() Function Section:-
यह C Program में Execute होने वाला पहला Function है जिसमे दो Curly Braces उसके शुरुआत और अंत हो दिखाता है
int main()
{
}
6)Sub Programs Section:-
इस भाग मे User कोई भी Function Defined कर सकता है जिसे main() में Call किया जाता है जैसे हमने showMessage() को Subprogram Section में Defined किया है कि यह कुछ Message Print करे और उसे main() में Call किया गया है
void showMessage()
{
printf("Here in subprogram section user-defined function is defined !\n");
}
Related Post
0 टिप्पणियाँ