Structure in C++ in Hindi

हेलो स्टूडेंट्स, इस पोस्ट में हम आज Structure in C++ in Hindi के बारे में पढ़ेंगे | इंटरनेट में C++ भाषा के नोट्स हिंदी में बहुत कम उपलब्ध है, लेकिन हम आपके लिए यह हिंदी में डिटेल्स नोट्स लाये है, जिससे आपको यह टॉपिक बहुत अच्छे से समझ आ जायेगा |

हेल्लो दोस्तों! आज हम इस post में Structure in C++ in Hindi (C++ में स्ट्रक्चर क्या है?) के बारें में पूरे विस्तार से पढेंगे. इसे आप पूरा पढ़िए यह आपको आसानी से समझ में आ जायेगा. तो चलिए शुरू करते हैं:-

Structure in C++ in Hindi

C++ में, Structure एक user-defined data type है जिसका प्रयोग अलग-अलग data types के elements को एक साथ स्टोर करने के लिए किया जाता है.

Structure एक data type को create करता है जिससे कि विभिन्न data types के items को एक साथ एक group में रखा जा सके.

उदाहरण के लिए – माना कि आप किसी person की information को स्टोर करना चाहते हैं. जैसे कि – name, address, age, salary आदि. तो आप इसके लिए variables को create कर सकते हैं और data को अलग स्टोर कर सकते हैं.

परन्तु अगर आप भविष्य में एक से ज्यादा persons की information को स्टोर करना चाहेंगे तो आपको प्रत्येक person के लिए variables को create करना पड़ेगा. इससे हमारा code बहुत ही खराब दिखेगा. इससे बचने के लिए हम structure का प्रयोग करते हैं.

Structure को create कैसे करते हैं?

structure को create करने के लिए struct कीवर्ड का प्रयोग किया जाता है. इसको create करने का सामान्य syntax निम्नलिखित हैं:-

struct struct_name  
{  
     // struct members
}   

उदाहरण के लिए –

struct Person  
{  
char name[30];  
char address[50];  
int age;
float salary;
           
};  

ऊपर दिए गये उदाहरण में Person एक structure है. जिसमें चार members हैं. ये members हैं:- name, address, age, salary. इसमें name और address char डाटा टाइप हैं. age एक int data type है. और salary एक float डाटा टाइप है.

Also read : Data Abstraction in C++ in Hindi

जब एक structure को create किया जाता है तो उसे memory नहीं दी जाती. इसे memory तभी दी जाती है जब इसमें सभी variables को add कर लिया जाता है.

Structure के members को कैसे access करते हैं?

Structure members को dot(.) operator का प्रयोग करके access करते हैं:-

#include <iostream>    
using namespace std;
struct Person
{
char name[50] ;
int age;
};
int main(void) {
// create structure instance
struct Person p;
//access array members
p.name = “Deepak”;
p.age = 25;
cout << "Person name: " << p.name << endl;
cout << "Person age: " << p.age << endl;

return 0;
}

इसका आउटपुट:-
Person name: Deepak
Person age: 25

Structure pointer क्या होता है?

एक ऐसे pointer को create किया जा सकता है जो structure को point करता हो. यदि हमारे पास pointer to structure होता है तो members को access करने के लिए dot operator की बजाय arrow (->) operator का प्रयोग किया जाता है.

#include <iostream> 
using namespace std; 
  
struct Point { 
int x, y; 
}; 
  
int main() 
{ 
struct Point p1 = { 1, 2 }; 
  
// p2 is a pointer to structure p1 
struct Point* p2 = &p1; 
  
// Accessing structure members using 
// structure pointer 
cout << p2->x << " " << p2->y; 
return 0; 
}

इसका आउटपुट –
1 2

structure का प्रयोग function argument के रूप में

हम structure को function में argument के रूप में pass कर सकते हैं. यह उसी तरह किया जाता है जैसे हम किसी सामान्य argument को pass करते हैं.

इसका example –

#include <iostream>
using namespace std;

struct Person
{
    char name[50];
    int age;
    float salary;
};

void displayData(Person);   // Function declaration

int main()
{
    Person p;

    cout << "Enter Full name: ";
    cin.get(p.name, 50);
    cout << "Enter age: ";
    cin >> p.age;
    cout << "Enter salary: ";
    cin >> p.salary;

    // Function call with structure variable as an argument
    displayData(p);

    return 0;
}

void displayData(Person p)
{
    cout << "nDisplaying Information." << endl;
    cout << "Name: " << p.name << endl;
    cout <<"Age: " << p.age << endl;
    cout << "Salary: " << p.salary;
}

Limitations of Structure in c++ in Hindi – स्ट्रक्चर की कमियां

इसकी कमियां निम्नलिखित हैं:-

  • struct data type को built in data type की तरह treat नहीं किया जा सकता.
  • structure variables में operators का इस्तेमाल नहीं किया जा सकता.
  • स्ट्रक्चर data hiding को support नहीं करता है. स्ट्रक्चर के members को किसी function के द्वारा भी access किया जा सकता है.
  • static members को structure body के अंदर declare नहीं किया जा सकता.
  • स्ट्रक्चर के अंदर constructors को create नहीं किया जा सकता है.

references:- https://www.geeksforgeeks.org/structures-in-cpp/

निवेदन:- यदि आपके लिए यह पोस्ट उपयोगी रहा हो तो इसे अपने दोस्तों के साथ अवश्य share कीजिये. और आपके c++ या किसी अन्य subjects से सम्बन्धित कोई questions हो तो उसे नीचे comment के माध्यम से बताइए. Thanks.

अपने दोस्तों के साथ share कीजिये.

Related

हम आशा करते है कि यह Structure in C++ in Hindi के हिंदी में नोट्स आपकी स्टडी में उपयोगी साबित हुए होंगे | अगर आप लोगो को इससे रिलेटेड कोई भी किसी भी प्रकार का डॉउट हो तो कमेंट बॉक्स में कमेंट करके पूंछ सकते है | आप इन्हे अपने Classmates & Friends के साथ शेयर करे |

Leave a Comment

Your email address will not be published. Required fields are marked *