Saturday 1 January 2022

Explain Structure of C++ Program, with suitable diagram and example.


Structure of a C++ program

C++ program is structured in a specific and particular manner. C++ programming structure is mostly identical to c programming except for the class concepts.

C++ प्रोग्राम को एक विशिष्ट और विशेष तरीके से संरचित किया जाता है। C++ प्रोग्रामिंग स्ट्रक्चर ज्यादातर क्लास कॉन्सेप्ट को छोड़कर c प्रोग्रामिंग के समान है।

Part 1: Header File or Preprocessor Section and Namespace declaration

हैडर फाइल या प्रीप्रोसेसर सेक्शन और नेमस्पेस डिक्लेरेशन

Part 2: Global Variables or Global Functions

Part 3: Class declaration

Part 4: Main Function of C++


 Part 1: Header File or Preprocessor Section

·         In C++, iostream is a very important header file.

C++ में, iostream एक बहुत ही महत्वपूर्ण शीर्षलेख फ़ाइल है

·         All preprocessor directives we can declare in this part.

सभी प्रीप्रोसेसर निर्देश हम इस भाग में घोषित कर सकते हैं।

·         The namespace declaration is mandatory for GCC compiler. no need for turbo c compiler

                जीसीसी कंपाइलर के लिए नेमस्पेस घोषणा अनिवार्य है। टर्बो सी कंपाइलर की कोई ज़रूरत नहीं

 

Part 2: Global Part

·         We can declare global variables and functions in this part.

हम इस भाग में Global Variable और functions की घोषणा कर सकते हैं।


·         We can access these variables or functions anywhere in this program.

इस भाग में डीक्‍लेयर किए गए वेरिएवल एवं फंक्‍शन्‍स को प्रोग्राम में कहीं भी एक्‍सेस किया जा सकता है।

 

Part 3: Class declaration

·         It is possible to declare Class in this part. But class concepts is not mandatory in C++.Class close parenthesis should end with a semi-colon.

इस भाग में Class घोषित करना संभव है। लेकिन C++ में क्लास कॉन्सेप्ट अनिवार्य नहीं है। क्लास क्लोज कोष्ठक एक सेमी-कोलन के साथ समाप्त होना चाहिए

 

Part 4: Main Function

·         Main Function is mandatory in C++ like C program.

यह फंक्‍शन सी++ के लिए अनिवार्य है।

Every C and C++ program starts with the main function. While program executes C++ compiler automatically calls the main function.

प्रत्येक सी और सी ++ प्रोग्राम Main Function  से ही Excecute होना शुरू होता है। जबकि प्रोग्राम सी ++ में कंपाइलर स्वचालित रूप से मुख्य फ़ंक्शन को कॉल करता है।

// Structure Of C++ Program
 
//Part 1: Header Files/Preprocessor/Namespace
#include <iostream>
using namespace std;
 
//Part 2: Global Part (Optional)
 
//Part 3: Class (Optional)
 
//Part 4: Main Function 
int main ()
{
  cout << "my first program in C++!";
  return 0;
    }


No comments:

Post a Comment