JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: C Language in hindi

Structure & Union in hindi in c language स्ट्रक्चर तथा यूनियन c कंप्यूटर भाषा में क्या होता है हिंदी में

स्ट्रक्चर तथा यूनियन c कंप्यूटर भाषा में क्या होता है हिंदी में Structure & Union in hindi in c language :-
Structure As Function (स्ट्रक्चर फंक्शन की तरह) :
जब किसी Structure  को function arguments मे pass किया जाता है tab तीन प्रकार से Structure  को function arguments से use कर सकते है |
1. In first method,Structure  के सभी members को calling function के actual parameters मे pass किया जाता है |उसके बाद ये member individual variable की तरह कार्य करता है लेकिन ये method उस case मे inefficient है जब Structure  मे members की सख्या बहुत ज्यादा होती  है |
2.इस method मे, पुरे Structure को function arguments मे pass किया जता है |जब एसे function को  calling होती है तब पूरी Structure calling function मे copy हो जाता है |और function के द्वारा किये गये changes का actual Structure variable पर कोई effect नहीं पड़ता है |इसलिए function मे return statement होना चाहिए |
3.इस method मे, भी पुरे Structure को function arguments मे pass किया जता है लेकिन pointer के concept से |इसलिए इसमें Structure के address को pass किया जाता है |calling function मे हुए change का effect Structure variable पर जरुर पड़ता है |इस method को Pointer and function मे detail मे पड़ेगे|इस article मे method 2 को हम detail मे पड़ेगे |
इसके rules होते है :-
1.called function का type declare होना चाहिए |Structure के लिए struct Structure_name को use किया जाता  है |
2. called function मे Structure को actual parameter की तरह pass करते है तब function definition मे , formal parameter मे Structure variable declare होगा |
3.return statement तभी होगा जब function कोई data या Structure को return करता है|
4.अगर Structure कोई Structure return करता है tab main() function मे ,return statement , Structure variable मे return Structure को assign करता है |

उदहारण के लिए :
#include<stdio.h>
#include<conio.h>
struct detail
{
char name[15];
int age;
char city[15];
int salary;
};
struct input ();                        //Function Declaration
void output (struct detail );    //Function Declaration

void main()
{
struct detail out_candidate;
out_candidate=input ();
output ( out_candidate );
getch();
}
struct input ()
{
struct detail candidate1;
printf(“Enter name “);
gets(candidate1.name);
printf(“Enter age”);
scanf(“%d”,&candidate1.age);
ptrintf(“Enter City “);
gets(candidate1.city);
printf(“Enter salary”);
scanf(“%d”,&candidate1,salary);
return(candidate1);
}
void output ( struct detail can1)
{
printf(“Details”)
printf(“Name : %s”,can1.name);
printf(“Age=%d”,can1.age);
printf(“City=%s”,can1.city);
printf(“Salary=%d”,can1.salary);
}

इस उदहारण मे void output ( struct detail can1) एक function है जिसमे structure argument की तरह pass हो रहा है लेकिन कोई value return नहीं हो रही है |
और
input () एक function है जिसमे कोई structure argument की तरह pass नहीं हो रहा है लेकिन एक structure return हो रहा है |

Size of Structure :
Size of Structure  का मतलब है bytes की सख्या जिन्हें कोई Structure memory मे occupy करता है |Structure की size अलग अलग कंप्यूटर के लिए अलग अलग जोती है |अतः Structure की size को sizeof() operator से calculate किया जाता है |इसका syntax है :-

sizeof(Structure variable_name );

इसका उदहारण है :
#include<stdio.h>
#include<conio.h>
struct detail
{
char name[15];
int age;
char city[15];
int salary;
};
void main()
{
struct detail candidate;
d=sizeof(candidate);
printf(“size of Structure candidate=%d  “,d);
getch();
}
यह पर ‘d’ एक variable है जो sizeof() operator के द्वारा दिए गया Structure  की size को calculate करता है|
अधिकाश 32 बिट कंप्यूटर के लिए उपर लिखे प्रोग्राम का आउटपुट होगा :
size of Structure candidate=34

Unions : यूनियन 
Unions भी एक user define data type है |जो structure data type की तरह , दो या दो से अधिक अलग अलग data type के variable को store करता है|
लेकिन difference ये है की unions data type मे सभी members के लिए एक ही storage location को occupy करता है |Structure data type मे , सभी members के लिए अलग अलग storage location occupy होगी |
इसका syntax है :-
union union_name
{
members;
}union variable_name ;

उदाहरण के लिए:
union data
{
int a;
float b;
char c;
}data1;

इस उदहारण मे , data एक union data type है |जिसमे तीन data variables (integer,float ,character) के लिए केवल 4 बाइट का storage occupy होगा |जो की float की maximum storage space 4 bytes होती है |

Union data type मे एक समय पर केवल एक ही variable के लिए use कर सकते है |

Union members को access करने के लिए भी member operator ‘.’ का use होता है |इसका उदहारण है :-
data1.a=-232;
data1.b=12.234;

ये दोनों statements एक साथ execute नहीं हो सकता है क्योकि union data type केवल एक storage space allocate करता है |पहले statement से इस storage अपके मे integer value 232 store हो जायेगा |और दूसरा statement execute नहीं होगा |

जब union data type को initial structure की तरह कर सकते है |लेकिन value का type,union data type के first data type के data type का होना चाहिए|

union data data1={12};                 // ये initialization statement सही है  // 
union data data1={12.343};         // ये initialization statement सही नहीं है क्योकि union data का first                                                                variable integer है //

union data type को array ,function के साथ use कर सकते है |

आगे article मे C language का most important concept ‘Pointer’ को study करेगे |

Sbistudy

Recent Posts

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

1 day ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

1 day ago

राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi

sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…

3 days ago

गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi

gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…

3 days ago

Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन

वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…

3 months ago

polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten

get all types and chapters polity notes pdf in hindi for upsc , SSC ,…

3 months 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