Union ( union keyword ) of C++ language.

A Union is a user defined data type of C++ language. It is also called heterogeneous or non homogeneous data type in which elements of different data types are stored together.Union is prepared by union keyword. Union is used to store records of an object and it allows different members to be accessed via a single pointer, or the union type variable. In union only one member is active at one time whereas in structure all members are active at same time. 


सी++ लैंग्वेज में यूनियन एक यूजर डिफाइंड डाटा टाइप है इसे हेटेरोजिनस या नॉन-होमोजिनस डाटा टाइप के नाम से भी जाना जाता है जिसमे एक से अधिक प्रकार के डाटा एलेमेंट्स को एक साथ रखा जा सकता है। यूनियन को union कीवर्ड की सहायता से तैयार किया जाता है। यूनियन का प्रयोग ऑब्जेक्ट के रिकार्ड्स को संग्रहित करने के लिए किया जाता है एवं इन्हें यूनियन के पॉइंटर या यूनियन टाइप के वेरिएबल द्वारा एक्सेस किया जा सकता है। यूनियन में एक समय में केवल एक ही मेम्बर एक्टिव होता है जबकि स्ट्रक्चर में सभी मेम्बर एक्टिव होते है।  


Declaration of union :-

union union_name{

datatype member_1;

datatype member_2;

----------------

----------------

datatype member_n;

}var1,var2-----varn;


Example:-

union student{

int rollno;

char name[50];

char gender;

float fees;

}s1,s2;


A union is a design or template which does not occupy bytes in computer memory until its variable is being created.Variable of union represents existence of union and the total number of memory bytes occupied by variable of union is equal to memory bytes occupied by the largest member of union.

यूनियन एक डिजाईन या टेम्पलेट होता है यह मेमोरी में स्थान ग्रहण नहीं करता है जब तक की इसका वेरिएबल तैयार ना हो। यूनियन का वेरिएबल , यूनियन के अस्तित्व को प्रदर्शित करता है। यूनियन के एक वेरिएबल द्वारा ली जाने वाली कुल मेमोरी बाइट की संख्या, उस यूनियन में उपस्थित सबसे बड़े मेम्बर द्वारा ली जाने वाली मेमोरी बाइट की संख्या के बराबर होती है।  


Definition of union :-

union union_name variable_name;

union union_name var1,var2----varn;

Example:-

union student s;

union employee e1,e2;

union student s[1000];


When user provide initial value to variable of union at the time of its declaration then it is called initialization of union.

यूनियन के वेरिएबल को प्रारंभिक मान प्रदान करना इनिशियलाईजेशन कहलाता है। 


Initialization of union :-

union union_name variable_name= value;

Example:-

union student s="ajay";


No comments:

Post a Comment