C++ Program के Basic Structure की संपूर्ण जानकारी हिंदी में

Basic Structure of C++Program in Hindi

एक C++ Program के Basic structure में आवश्यक भाग शामिल होते है जो एक Functional program का निर्माण करने के लिए आवश्यक है।
अतः नीचे C++ Program की Basic Structure को 6 भागों मे बांटा गया है   
1) Documentation Section
2) Link Section या Preprocessor
3) Definition Section
4) Global Declaration Section
5) Function Definiation Section
6) Main function

Documentation Section

C++, में Documentation section, Code के उस भाग को refer करता है जहां आप Comments लिखते और Documents को explain करते है हुए यह बताते है कि आपका Code क्या करेगा यह Section Program के सबसे शुरुवात मे रहता है

ये  Comments, Program के अन्य भाग के समान execute नही किए जाते लेकिन ये Programmers के लिए जो आपके Program Code को भविष्य में पढ़ेगा या उसके साथ कार्य करेगा, के लिए एक मार्गदर्शक के रूप में कार्य करते है 

Document Section में Comment Lines का एक Set शामिल रहता है जिसमें कुछ जानकारी जैसे Program का Description, Programmer का नाम Program के निर्माण का Date,  और अन्य Details रहते है
Documentation को निम्न प्रकार से Comments में प्रदर्शित कर सकते हैं
Example

//Write a Program to print Hello World
/*
Programmer's name:- God is Love
File name :- helloworld.cpp
Date :- 30/04/24   
                                   */

Link Section या Preprocessor

C++ Programs के Standard C++ library में पहले से निर्मित कई elements जैसे classess, keywords, constants, functions आदि होते है

अतः यदि आप इन elements को अपने C++ Programs में शामिल करना चाहते है तो उससे संबंधित Header files अर्थात ये elements जिन Header files में उपस्थित रहते है उन Header files को अपने अपने C++Program में शामिल करना जरूरी है

ताकि आप उन elements को Use कर सकें अतः इन Header files को निम्न प्रकार से C++ Program में शामिल करते है।

Example:
#Include<iostream.h>

यहां पर <iostream.h> का अर्थ Standard input output stream है इसका मतलब <iostream.h> , Header file में ऐसे Input और Output Functions है जिसे हम अपने Program में Use करना चाहते है ये functions cout() और cin() है 

Definition Section

C++ में  Definition section Program के उस भाग को refer करता है जहां पर आप कुछ निश्चित elements जैसे Variables, Functions, Classes, और Constants को Define करते है 

इस section में आप elements का details जैसे उनका नाम, Data type, शुरुवाती मान (Initial value) और वे कैसे कार्य करेंगे, के बारे जानकारी देते है 

C++ Program के Definition Section में निम्न elements को Define कर सकते है

Variable Definitions

इसमे Variables को Declare करना और उसे  initial values Assign करना शामिल हैं।

Example
   int SID = 70;
   float fees = 767.67;

Function Definitions

इसमें function को Define करना शामिल है 
इसके अंतर्गत function का return types, function का नाम, उसके parameter और code या instructions जिन्हे execute होना है आदि शामिल है

Example  

  int calSquare (int num)
 {
    int square = num * num;
    return square;
}


Class Definitions

यदि हम अपने Program में Object-oriented programming का Concept Use करना चाहते है तो हमे Classes Define करना होता है जो Data और उसके व्यवहार को encapsulate कर सके

इसमें Class Define करने के बाद उसके Body के अंदर उसके Members जैसे
Members variables, Member functions, Constructors और अन्य जो Class से सम्बंधित है को Define किया जाता है।

Example

class Myaddition
 {
   public:
       int num1;
       int num2;
      
       int addNum()
      {
         return num1+num2; 
       }
   };
  

Global Declaration Section

C++ का Global declaration section में आप  Variables और Functions को कोई भी Class या Function के बाहर declare कर सकते हैं 

ये Declarations संपूर्ण प्रोग्राम मे हर जगह Access होते है अर्थात आप इन्हे Program में कही भी Use कर सकते हैं 

Example

int globalVar = 10;
void displayGlobalVar()
 {
    cout << "Value of Global Variable: " << globalVar <<endl;
}
int main() 
{
    displayGlobalVar();
    return 0;
}

Function Definition Section

C++ में Function definition section, Program के उस भाग को refer करते है जहां पर आप पहले से declare किए गए Function का Implementation details प्रदान करते हैं 

इसमे Actual code लिखा जाता है जो यह Define करता है कि जब function को Call किया जायेगा तब function को क्या करना चाहिए

Example

//function definition
   int addNum(int a, int b) 
   {
      int sum
      sum = a+b;
       return sum;
    }
int main() 
{  
    int num1 = 15;
    int num2 = 13;
//calling function
 int sum = addNum(num1, num2);
cout << "Sum of both numbers is " << sum <<endl;
    return 0;
}

Main () Function Section

प्रत्येक C++ Program का यह एक महत्त्वपूर्ण भाग है  क्योंकि Program execution की शुरुवात यही से होती है 
सभी C++ statements जो main() के Curly braces {} के अंदर लिखे होते है Complier द्वारा execute किए जाते है

Basic structure of C++ program 
// Documentation Section
/*
Solution :- Write a program to add two numbers
File name :- addNum.cpp
Author's name :- God is love
Date :- 01/05/24
                               */
// Global Declaration Section
//Linking section

#include<iostream>
using namespace std;

// Function Definition Section
int addNumbers(int a, int b) 
 {
    return a + b;
}

// Main function
int main() 
{
    int num1 = 15;
    int num2 = 13;

    // Calling function
    int sum = addNumbers(num1, num2);

    // Printing the result
   cout << "Sum of both numbers is:" << sum << endl;
    return 0;
}
Output:
Sum of both numbers is:28

Explanation :-

ऊपर के Program की Basic Structure को एक एक करके निम्न प्रकार से समझते हैं

1) Documentation Section :-
इस भाग में Comments होते है साथ ही इस भाग में आप Program और Programmer संबन्धित जानकारियो जैसे Programmer का नाम, File का नाम, Date, क्या Program बना रहे है आदि  होती है

// Documentation Section
/*
Solution :- Write a program to add two numbers
File name :- addNum.cpp
Author's name :- God is love
Date :- 01/05/24
                               */

2) Link Section:-
इस भाग में Header File होते है जो C++ Language के System Libraries में उपलब्ध होते है इन Header Files के अंदर बहुत सारे पहले से निर्मित Functions होते है 

यदि आप अपने program में किसी function  को Use करना चाहते है तो आपको उससे सम्बंधित Header file को अपने C++ Program में  include कराना होता है जैसे cin() और cout() जो Input/Output कार्यों से सम्बंधित है, को Use करने के लिए आपको <iostream> Header file को अपने Program में आवश्यक रूप से शामिल कराना होता है

#include <iostream> 

3) Global Declaration Section:-  
C++ में Global declaration section, Program का एक भाग है जहां पर आप 
Variables, functions आदि declare कर सकते हैं ताकि उसे program के किसी भी भाग से Access कर सके

4) Function Definition Section:-
यहां पर `addNumbers` function को define किया गया है जो दो integer parameters (`a` और `b`)  लेता है और `return a + b; का Use करके sum को return करते हैं इसी स्थान पर आप अपने function के लिए Code लिखते हैं

4) Main Function:-
main()` function, C++ Program का entry point होता है यह two Integers variables (`num1` और `num2`) को  values 15 और 13 के साथ क्रमश: declare और Intialize करता है 

 फिर यह `addNumbers` function को  `num1` और `num2` arguments के साथ call करता और returned sum की value को  variable `sum` में store कर देता है

अंत में `cout` function का Use करके result को print किया जाता है

आवश्यक जानकारी
C++ program में header files के बाद using namespace std; का Use करके standard library functions(जैसे cout, cin आदि) को बिना std:: लगाए Use कर सकते हैं

अपने Program में <conio.h> header file भी Add करे तथा getch(); को return 0; के बाद लिखे क्योंकि यह Output Window को प्रदर्शित करता है


 Related Posts

> C++ क्या है? उसके इतिहास, गुण, उपयोग, फायदे और नुकसान 

> C++ में Tokens क्या है? और उसके प्रकार

> C++ Variables क्या है?, उसके प्रकार, उसे कैसे Declare, Define करते हैं

> C++ में Constants क्या है? उसके प्रकारों की संपूर्ण जानकारी

> C++ में Basic Input और Output (cin,cout,cerr) की जानकारी

> Data type in C++ की संपूर्ण जानकारी 

> C+ में Operators और उसके प्रकार जानें Practical सहित 

> C++ में Conditional और उसके प्रकारों को जानें Practical सहित 

> C++ में Looping statements और उसके प्रकार Practical सहित 

> C++ में Jump Statements और उसके प्रकारों की संपूर्ण जानकारी Practical सहित

> C++ में Array क्या है? और उसके प्रकारों की जानकारी Practical सहित

> C++ में Function क्या है उसके प्रकार, उपयोग प्रोग्राम सहित 

> C++ में Structure क्या है Practical सहित

> OOPs Concepts in C++ in Hindi- C++ में OOPs के बारे में

> Oops के फायदे और नुकसान की जानकारी 

> OOP और POP के बीच अंतर 

> C++ में Class और Object की सम्पूर्ण जनकारी

> C++ में Array of Objects क्या है? 

> C++ में Pointers, Pointer to an objects, Pointer to an Array की संपूर्ण जानकारी हिंदी में।

C++ में Passing objects क्या है

> C++ में Reference और Type Casting की संपूर्ण जानकारी

> C++ में Access specifier की संपूर्ण जानकारी 

> C++ में Static Data Members और Member Functions के बारे में Practical सहित 

> C++ में Memory allocation और Memory management operators (new और delete) Practical सहित 

> Friend Function in C++ in Hindi 

> Friend Class in C++ in Hindi Practical सहित 

> Inline function in C++ in Hindi 

> Function Overloading in C++ in Hindi Practical सहित 

> Operator Overloading in C++ in Hindi Practical सहित 

> C++ में Constructor क्या है और उसके प्रकारों की संपूर्ण जानकारी

> C++ में Destructor क्या है ?उसकी संपूर्ण जानकारी

> C++ मे Inheritance क्या है उसके प्रकारों को जानें प्रोग्राम सहित

> C++ में Polymorphism क्या है? और उसके प्रकारों को जानें

> C++ में Virtual function की संपूर्ण जानकारी

> C++ में File handling की संपूर्ण जानकारी 

> C++ में Exception handling  की संपूर्ण जानकारी