What is Procedural Programming in C Language in Hindi
/ BCA / Programming with C and CPP
Core Concepts of Procedural Programming in C Language
What is Procedural Programming in C Language in Hindi
Procedural Programming एक ऐसा programming style है जिसमें कोई भी program step-by-step तरीके से instructions (निर्देश) के रूप में लिखा जाता है। इसका मतलब यह है कि हम किसी काम को पूरा करने के लिए उसे छोटे-छोटे steps में बाँट देते हैं और हर step को एक-एक करके लिखते हैं। C Language इसी प्रकार की एक भाषा है जिसे procedural programming language कहा जाता है।
Procedural Programming के मुख्य Features
- Program को छोटे-छोटे parts (functions) में बाँटना
- हर function का एक specific काम होता है
- Programs को ऊपर से नीचे (top to bottom) तरीके से execute करना
- Variables और data को globally या locally define करना
- Instructions को एक निश्चित क्रम (sequence) में लिखना
C Language में procedural programming का सबसे बड़ा फायदा यह है कि यह आसान होता है और किसी भी complex काम को आसान बनाने में मदद करता है। जब हम कोई बड़ा काम करते हैं तो हम उसे छोटे भागों में बाँट लेते हैं और हर भाग को एक function बना देते हैं। फिर इन्हीं functions को call करके हम अपने पूरे काम को manage कर सकते हैं।
Top-down approach in C Language in Hindi
Top-down approach एक ऐसा तरीका है जिसमें हम पहले पूरे प्रोग्राम की योजना बनाते हैं और फिर उसे छोटे-छोटे हिस्सों (modules या functions) में बाँटते हैं। इस approach में सबसे पहले main logic या मुख्य कार्य को define किया जाता है, और फिर धीरे-धीरे उसे break करके छोटे कामों (sub-tasks) में divide किया जाता है।
Top-down approach की विशेषताएँ
- सबसे पहले program का overview तैयार किया जाता है
- Main task को छोटे-छोटे subtasks में बाँटा जाता है
- हर subtask के लिए अलग-अलग functions बनाए जाते हैं
- Functions के माध्यम से logic को manage किया जाता है
- Debug करना और errors ढूँढना आसान हो जाता है
C Language में जब हम एक नया program लिखते हैं, तो हम पहले main() function लिखते हैं और फिर उसी के अंदर जरूरत के अनुसार दूसरे functions को call करते हैं। यही top-down approach कहलाती है।
उदाहरण:
#include <stdio.h>
void input();
void process();
void output();
int main() {
input();
process();
output();
return 0;
}
void input() {
printf("Data ले रहे हैं...\n");
}
void process() {
printf("Data प्रोसेस कर रहे हैं...\n");
}
void output() {
printf("Result दिखा रहे हैं...\n");
}
ऊपर दिए गए example में सबसे पहले main function लिखा गया है और फिर उसके नीचे तीन अलग-अलग functions बनाए गए हैं - input(), process(), और output(). यही तरीका top-down approach कहलाता है।
Code reusability and modularity in C Language in Hindi
Code Reusability का मतलब होता है एक बार लिखे गए code को बार-बार दोबारा इस्तेमाल करना। वहीं Modularity का मतलब है program को कई छोटे-छोटे parts (modules) में बाँटना ताकि हर part एक specific काम कर सके। C Language में ये दोनों features बहुत important हैं और इन्हें Functions के माध्यम से achieve किया जाता है।
Code Reusability के फायदे
- Time की बचत होती है
- Code साफ-सुथरा और पढ़ने में आसान होता है
- Bar-बार एक ही logic लिखने की जरूरत नहीं होती
- Maintain करना आसान होता है
Modularity के फायदे
- Program का structure अच्छा होता है
- हर function को अलग से debug किया जा सकता है
- Function library बनाकर कहीं भी इस्तेमाल किया जा सकता है
- Teamwork में काम आसान हो जाता है
उदाहरण:
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int main() {
int x = 10, y = 20;
int result = add(x, y);
printf("Addition: %d", result);
return 0;
}
ऊपर के code में add() नाम का एक function है जो दो numbers को जोड़ने का काम करता है। यह function बार-बार किसी भी जगह इस्तेमाल किया जा सकता है। यही code reusability है और यह function एक modular unit है, जो सिर्फ addition का काम करता है।
Function-based structure of C Language in Hindi
C Language एक function-based language है, जिसका मतलब है कि पूरा प्रोग्राम functions के ऊपर आधारित होता है। एक function ऐसा block होता है जिसमें कोई खास logic या task लिखा जाता है, और जब जरूरत होती है तो उस function को call किया जाता है।
Function-based structure की आवश्यकता क्यों?
- हर logic को एक अलग function में रखा जा सकता है
- Complex programs को छोटे-छोटे हिस्सों में divide किया जा सकता है
- Functions को बार-बार इस्तेमाल किया जा सकता है
- Debug करना आसान होता है
Function के प्रकार
| Function का प्रकार | विवरण |
|---|---|
| Library Function | पहले से बने हुए functions जैसे printf(), scanf(), etc. |
| User-defined Function | Programmer द्वारा खुद बनाए गए functions |
Function Structure:
- Function Declaration (घोषणा)
- Function Definition (परिभाषा)
- Function Call (कॉल करना)
उदाहरण:
#include <stdio.h>
// Declaration
void greet();
// Main Function
int main() {
greet(); // Function Call
return 0;
}
// Definition
void greet() {
printf("Hello! Welcome to C Programming.\n");
}
इस code में greet() एक user-defined function है जिसे पहले declare किया गया है, फिर main() में call किया गया है, और अंत में define किया गया है। इसी को function-based structure कहते हैं।