Notes in Hindi

Concept of Nesting of Function in Hindi

/ BCA / Programming with C and CPP

Concept of Nesting of Function in C in Hindi

Concept of Nesting of Function in Hindi

What is Nesting of Function in C?

C language में **Nesting of Function** का मतलब होता है – एक function के अंदर दूसरे function को call करना। इसे हम function inside function calling भी कहते हैं। यह तरीका तब काम आता है जब किसी function की जरूरत हमें किसी दूसरे function के अंदर पड़ती है। इससे code modular और organized बनता है।

Why Nesting of Function is Used?

  • Code को छोटा और readable बनाने के लिए
  • Code को बार-बार reuse करने के लिए
  • Complex logic को छोटे parts में divide करने के लिए
  • Debugging को आसान बनाने के लिए

Calling Function Inside Another Function in Hindi

जब हम एक function के अंदर दूसरे function को call करते हैं, तो उसे "function nesting" कहा जाता है। इसका मतलब है कि एक function तब तक अपना काम पूरा नहीं करेगा जब तक उसके अंदर call किया गया दूसरा function complete न हो जाए।

Example for Better Understanding

मान लीजिए हमारे पास दो functions हैं – display() और message()। अब हम चाहते हैं कि जब display() function चले, तो वो अपने अंदर से message() को call करे। इसका मतलब है कि एक function दूसरे function को अपने अंदर बुला रहा है।

#include <stdio.h> void message() { printf("Hello! This is message function.\n"); } void display() { printf("Inside display function.\n"); message(); // Nesting of function } int main() { display(); return 0; }

Output:

Inside display function. Hello! This is message function.

Explanation:

  • सबसे पहले main() function call होता है।
  • main() के अंदर display() को call किया गया है।
  • display() function के अंदर एक और function message() को call किया गया है।
  • इसलिए पहले display का काम होता है, फिर message function execute होता है।

Syntax of Nesting of Function in Hindi

Function Nesting का syntax बिलकुल simple होता है:

void function1() { // कुछ statements function2(); // दूसरा function call किया गया // कुछ और statements } void function2() { // statements of function2 } int main() { function1(); // पहला function call होता है return 0; }

ध्यान रखें कि जब हम function2 को function1 के अंदर call करते हैं, तो function2 पहले execute होगा, और फिर function1 का अगला हिस्सा चलेगा।

Important Rules of Nested Function Calling

  • एक function के अंदर हम किसी भी दूसरे function को call कर सकते हैं, पर उसे पहले से define या declare करना जरूरी होता है।
  • C language में एक function को दूसरे function के अंदर define नहीं किया जा सकता (जैसे Python में किया जा सकता है)।
  • Nested calling allowed है, nested definition allowed नहीं है।

Example of Nested Function in C in Hindi

नीचे दिया गया एक full working example है जिसमें nesting का इस्तेमाल किया गया है।

#include <stdio.h> void input(); // Declaration void process(); // Declaration void output(); // Declaration int main() { input(); // Calling input function return 0; } void input() { printf("This is the input function.\n"); process(); // Calling process from input } void process() { printf("This is the process function.\n"); output(); // Calling output from process } void output() { printf("This is the output function.\n"); }

Output:

This is the input function. This is the process function. This is the output function.

इस Code की Step-by-Step Working:

  • main() function के अंदर सबसे पहले input() function call होता है।
  • input() function के अंदर process() को call किया गया है।
  • process() function के अंदर output() को call किया गया है।
  • इसलिए execution का क्रम होगा: input → process → output

Table: Difference Between Nested Function & Normal Function Call

Aspect Normal Function Call Nested Function Call
Definition Function को सीधे main से call किया जाता है Function को किसी दूसरे function के अंदर call किया जाता है
Usage Simple और isolated tasks के लिए Complex logic को simplify करने के लिए
Control Flow Straightforward Hierarchical और dependent

Beginners के लिए Useful Tips:

  • हर function को call करने से पहले declare करना जरूरी होता है।
  • एक function के अंदर जितने भी दूसरे functions को call करना है, उन्हें पहले से define या declare करें।
  • C में function को function के अंदर define करने की अनुमति नहीं होती, सिर्फ call किया जा सकता है।
  • हर function का एक clear और specific काम होना चाहिए।

Real Life Example for Better Understanding:

मान लीजिए आप खाना बना रहे हैं। इसके लिए आपको पहले सब्ज़ी काटनी है, फिर पकानी है, फिर परोसनी है। ये steps अलग-अलग functions हो सकते हैं:

  • cutVegetables()
  • cookFood()
  • serveFood()

अब आप prepareMeal() नाम का एक function बनाते हैं जिसमें ऊपर दिए गए तीनों steps call होते हैं। यानी एक function (prepareMeal) के अंदर बाकी तीनों functions को nest किया गया है। यही होता है nesting of function in real life analogy.

FAQs

Nested Function का मतलब होता है किसी एक function के अंदर दूसरे function को call करना। इसे Function Calling Inside Another Function भी कहते हैं। C में हम एक function के अंदर सिर्फ दूसरे function को call कर सकते हैं, लेकिन define नहीं कर सकते।
नहीं, C language में हम एक function के अंदर दूसरा function define नहीं कर सकते। हम सिर्फ दूसरे function को call कर सकते हैं। Function Nesting में सिर्फ calling allow है, definition नहीं।
Nested Function का उपयोग program को modular, readable और manageable बनाने के लिए किया जाता है। इससे code छोटा और reusable बनता है और complex logic को आसानी से छोटे भागों में divide किया जा सकता है।
Syntax बहुत simple होता है:
void function1() {
  // some code
  function2();
}
void function2() {
  // some code
}

यहां function1 के अंदर function2 को call किया गया है।
C में आप जितने चाहें उतने functions को एक-दूसरे के अंदर call कर सकते हैं, लेकिन उनका structure logical और manageable होना चाहिए। ध्यान रहे कि nesting बहुत अधिक complex हो तो program की readability और debugging मुश्किल हो सकती है।

Please Give Us Feedback