JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Categories: c++ language in hindi

C++ : Union or Enumeration in hindi , what is union or Enumeration in c++ language in hindi

what is union or Enumeration in c++ language in hindi , C++ : Union or Enumeration in hindi :-
इससे पहले के article मे , compund data type मे से array और struture को discuss किया है इस article मे compund data type मे से unions और enum data type को discuss करेगे |
UNION
union data type भी structure data type की तरह बहुत सारे अलग अलग data को handle कर सकता है | लेकिन एक समय पर केवल एक ही data value को carry कर  सकता है | structure मे एक साथ integer ,long और double type की details को hold कर सकता है |उसी प्रकार union मे या तो integer value और float data और double value hold सकती है | इसका syntax struture की तरह होता है लेकिन इसका मतलब अलग अलग होता है :-
union datapack
{
int value1;
long int value2;
double value3;
};
यह पर datapack तीन प्रकार की value को hold कर सकता है |
1.int value1 : integer type value है |
2.long value2 : long type value है |
3.double value3 : double type value होती है |
union data type का struture की तरह variable को define कर सकते है |उदाहरण के लिए datapack d1;
d1.value1 से variable d1 के value1 पर data store होता है |
d2.value2 से variable d1 के value2 पर data store होता है |
इस उदाहरण मे हम देख सकते है एक समय पर d1 का type integer है और दुसरे समय पर d1 का type long integer है | और union द्वारा एक समय मे केवल ही value के साथ डील की जाती है इसलिए in data value के लिए enough data space होता है | और union की size ,union के सबसे बड़े memeber की size के सामान होती है |
union का use ,space को कम करने के लिए किया जाता है | और उस जगह किया जाता है जहा पर एक समय मे केवल एक ही variable use करना होता है |
उदाहरण के लिए widgets () को use किया जाता है इसमें कुछ  integer id होती है कुछ string id होती है | और एक समय पर केवल एक ही data variable use किया जाता है |
उदाहरण के लिए
#include<iostream.h>
#include<conio.h>
struct widget{
std::string name;
int price;
int type;
union id{
long id_num;
char id_char [20];
}int value ;
};
void print(book);
void main()
{
widget w;
cout<<“Enter name of brand”<<endl;
cin.get(w.name);
cout<<“Enter Price”<<endl;
cin>>w.price;
cout<<“Enter Type :”<<endl;
cin>>w.type;
cout<<“Enter Size :”
if(w.type==1)
{
cin>>w. id_num;
}
else
{
cin>>w. id_char;
}
print(b);
getch();
}
void print( widget w )
{
cout<<“Brand Details”<<endl;
cout<<“Brand Name :”<<w.name<<endl;
cout<<“Price : “<<w.price<<endl;
cout<<“Size : “<<w.size<<endl;
}
ENUMERATION
C++ मे enum ,const के तरह कार्य करता है | जो की constant को बनता है | enum से नए data type को भी बनाया जा सकता है |enum का syntax structure की तरह होता है जैसे
enum sex = { male ,female };
enum के syntax मे दो भाग होते है :
1.enum name : इस उदाहरण मे sex enum का नाम है जिसे प्रोग्राम मे use किया जाता है|
2.enum data : ये enum का data value है जिसके index 0,1 है |male के लिए ‘0’ और female के लिए ‘1’ होती है |
enum data type मे सभी data type को 0 से लेकर infinite value को index बनाया जाता है |अगर first element के लिए index ‘0’ होती है | दूसरी value के लिए ‘1’ होती है और तिरसी value के लिए ‘2’ होती है | इस प्रकार ये कर्म आगे चलता रहता जब तक की enum की value ख़तम नहीं होती है |
enum के नाम को एनम type के variable को define करने के लिए use किया जा सकता है |जैसे
sex s1;
यह पर s1 की property , sex की तरह होती है |
enum variable की value को केवल enum data type मे define की गयी value से initial किया जा सकता है |अगर इसे किसी दूसरी value से initial किया जाता है error message आ जाता है |जैसे
s1 = male;   // Valid initial
s1 = 200 ;   // Invalid initial
और अगर enum variable मे enum की data value को modify करके initial किया जाता है तब भी error message आ जाता है | जैसे
s1 = female;  // Valid Assignment
female++;
s1= female;  // Invalid Assignment
पहले statement मे , female की value को enum data type को define किया गया है | लेकिन female को increment किया जाता है और उसके बाद female को s1 मे assign किया जाता है tan statement error message देगा |
नीचे दिए गये उदाह्रानो को भी देखते है |
int age= male;             // Valid
s1 = 2;                        //  Invalid
age = 3 + female ;     //  Valid
enum data type के सभी member value के साथ एक इन्तेग्र value associte होती है इसलिए enum data value को integer variable मे assign किया जा सकता है | लेकिन enum data variable में integer value assign नहीं कतर सकते है |
उपर वाले उदाहरण मे
int age= male से age की value ‘0’ होती है |
age = 3 + female से age की value 4 होती है |
एक और statement को discuss करते है जो की थोडा मुश्किल है |
s1= male +female;
यह पर male और female दोनों को ही enum के डेफिनिशन मे define किया गया है | लेकिन ये statement अभी भी गलत है क्योकि s1 एक enum type variable है जिसमे केवल enum type value assign हो सकती है |
और इसके पहले age = 3 + female मे age का type integer होता है | अतः addition possible होता है |
TYPECAST
TYPECAST possible है अगर किसी valid value को enum से casting की जाती है तो type casting हो जाती है |उदाहरण के लिए :
std::string s = sex(0);
इस statement से s मे male assign हो जाता है क्योकि ‘0’ वाले से associate enum value male थी | लेकिन एगर value गलत हुई तो error message आ जाता है | जैसे
std:: string s= sex(10);
इस ststement से error message आ जाता है |
इस article मे , UNION को discuss किया है |और ENUMERATION के basic को भी discuss किया है |अब next article मे C++ : Enum ( Advance) मे  ENUMERATION के उदाहरानो और advance concept को discuss करेगे |
इससे पहले के article मे enum को discuss किया था | एब इस article मे ,enum data type के data value को set करना और string class के विशेष function सको discuss करेगे |
Setting a Data in Enumeration
Enum data type मे value के integer value को set किया जा सकता है | इसके लिए assignment operator का use किया जाता है | उदाहरण के लिए
#include<iostream.h>
#include<conio.h>
void main()
{
enum sex = {male, female };
int s;
cout<< “Enter Sex ( For male , ‘0’ and For female ‘1’ ) : “<<endl;
cin>>s;
if(sex==0)
{
cout<<“You are male.”<<endl;
}
else
{
cout<<“You are Female “<<endl;
}
getch();
}
इस उदाहरण में , enum को define किया गया है | जिसमे दो data values , male और female होती है | अगर द्वारा input की गयी value ‘0’ होती है तब user male होता है और अगर यूजर द्वारा input की गयी input ‘1’ होती है तब यूजर female होता है | इस उदाहरण मे , male की value ‘0’ और female की value ‘1’ होती है |
यहा पर enum data type के data values की integer value को यूजर द्वारा set किया जा सकता है |जैसे male की value 100 और female की value 200 को set किया जा सकता है |
उदाहरण के लिए :
#include<iostream.h>
#include<conio.h>
void main()
{
enum sex = {male, female };
int s;
cout<< “Enter Sex ( For male , ‘100’ and For female ‘200’ ) : “<<endl;
cin>>s;
if(sex==100)
{
cout<<“You are male.”<<endl;
}
else
{
cout<<“You are Female “<<endl;
}
getch();
}
अगर नीचे दिए गये statement को consider करेगे तब
enum color { red ,yellow =100 , green };
इस उदाहरण मे red की integer value ‘0’ है और yellow की integer value ‘100’ और green की integer value ‘101’ होती है |
ओए अगर नीचे दिए statement  को consider करेगे तब ,
enum   color { red ,yellow = 0 , green , pink =1};
इस उदाहरण मे , red और yellow की value ‘0’ होती है और green और pink की value ‘1’ होती है | C language मे , enum value की value केवल integer हो सकती है लेकिन C++ मे , enum value की value ,long integer हो सकती है |
Value Range
enum के लिए valid data value केवल यो ही होती है जिसकी value को enum data type मे define किया जाता है | लेकिन enum data type की value को बढ़ाया भी जा सकता है इसके लिए type cast को use किया जाता है |अतः enum data type की एक range होती है | किसी भी integer value को range के स्थान मे set की जा सकती है | उदाहरण के लिए
enum   color { red=1 ,yellow = 3 , green =5 , pink = 7};
bit range ;
range = color(8);
यहा पर
‘8’ range है जिसे color type मे convert कर दिया जाता है |
सबसे पहले उपर limit को calculate करते है अतः इसे calculate करने के लिए |
Sbistudy

Recent Posts

द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन क्या हैं differential equations of second order and special functions in hindi

अध्याय - द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन (Differential Equations of Second Order…

14 hours ago

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

3 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

5 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

1 week ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

1 week ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now