What is C Unions In Hindi – C Unions In Hindi : – Hello Friends! आज के इस आर्टिकल में हम आपको C Unions के बारे में बताने जा रहे है। C Unions का Use कैसे किया जाता है ये भी हम आपको इस आर्टिकल में बताएंगे।
तो चलिए जानते है What is C Unions In Hindi – C Unions In Hindi – C Unions क्या है?
C Unions Kya Hai? – What is C Unions In Hindi
C Language में एक Special Type का Data Type Provide किया गया है , और इस Data Type को Union बोला जाता है। Union Data Type की Help से आप एक ही Memory Location में Different Types के Data Type को Easily Store कर सकते है।
Unions Data Type के अंदर Different Different Variable को Create किया जा सकता है। Unions C Language में Structure की तरह ही काम करते है लेकिन Difference ये होता है की Structure का हर Member एक Separate मेमोरी Location लेता है और उन सब का Size Different Different होता है।
defining a union
Unions को Define करने के लिए Union Keyword का Use किया जाता है। जिस तरह Structure को Define किया जाता है ठीक उसी तरह Unions को भी Define किया जाता है। Unions को Define करने का Basic Syntax है जो आप नीचे देख सकते हो।
union union_name
{
data_type var1;
data_type var2;
...
....
data_type varn;
}u1.u2,.....un;
सबसे पहले Union Keyword और Unique Union Name को Define किया जाता है। उसके बाद Variable को Define किया जाता है Curly Brackets के अंदर उसके बाद Ending Curly Brackets के बाद Comma Use करके Union Variable को Create किया जाता है।
union input
{
int a;
float b;
}in;
accessing union member variable
Union Member को भी उसी तरह Access किया जाता है जिस तरह Structure Members को Access किया जाता है। सबसे पहले Union का नाम लिखा जाता है , उसके बाद dot(.) Operator को Use करके Member का नाम Mention किया जाता है।
in.a=10;
Union Member को Print कराने के लिए आप नीचे दिए गए Example को देख सकते है।
printf(“%d”,in.a);
अगर Union के सभी Member को एक साथ Value को Assign करके एक साथ प्रिंट करवाना हो तो Output Invalid Show होता है और अगर किसी दूसरी variable की Value को Assign किया जाता है तो मेमोरी में Value उसी की रहती है।
#include<stdio.h>
union input
{
int a;
float b;
}in;
int main()
{
in.a=15;
printf(“value of a is :%d\n”,in.a);
in.b=20;
printf(“value of b is : %f”,in.b);
return 0;
}
ऊपर Example में a की value को set किया गया है और उसे Print करवाया गया है। फिर उसके बाद b variable की value को set किया गया है।
Conclusion
इस आर्टिकल में हमने आपको C Unions के बारे में बताये। उम्मीद है आपको ये आर्टिकल पसंद आया होगा। C Language से जुड़ा कोई भी सवाल आपके मन में है तो आप हमे Comment करके पूछ सकते है।