JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: C Language in hindi

Pointer In Structure (Data Type) in hindi in c language पॉइंटर को स्ट्रक्चर के रूप में कैसे काम में लेते है

पॉइंटर को स्ट्रक्चर के रूप में कैसे काम में लेते है Pointer In Structure (Data Type) in hindi in c language :-
Pointer As structure : जिस प्रकार से array name कसी array के first element के address को
contain करते है उसी प्रकार structure data type मे भी array ऑफ़ structure के
first variable के address को contain करता है |
जैसे
struct add{
int house ;
char street _name [20];
int pin_code ;
char city[15]
}add[2],*a;
इस उदाहरण मे add एक structure होते है जिसमे house ,street_name ,pin_code
और city जो की अलग अलग data type के है को contain करता है |
int house : ये integer data type है इसमें house no की value सेव
होती है |
char street_name[]:ये string है जिसमे address का street name store
होता है |
int pin_code : ये भी integer data type है जिसमे की pin code की
value store होगी |
char city[] :ये string है जिसमे city का नाम store होता है |
memeber block के बाद , add[2], structure add का array है जो की तीन structure
add data type store कर सकता है |इस array को handle करने के लिए pointer ‘a’ को
use किया जाता है |
a=add;
इस statement से,structure add के type का पहले variable ‘add[o]’ का
address store होता है |जब a++;
statement execute होने पर , record 2 (array add[1]) की
address मे increment हो जायेगा |और pointer ‘a’ मे array element a[1] का address
store हो जायेगा |
जैसे
a=a[0] का address
a+1 पर ,a=a[1] का address
a+2 पर a=a[2] का address
जब किसी structure के members को access करने के लिए arrow operator (‘->’) का use करा सकते है इसे members selection
operator कहते है |
a->street_name का मतलब है record 1,a[0] का memeber street_name
सेलेक्ट होगा |
a->city का मतलब है record
1,a[0] का memeber city सेलेक्ट होगा |
जब a++ होने के बाद
a->street_name का मतलब है record 2,a[1] का member street_name सेलेच्व्त करने पर |
a->city का मतलब है record 2, a[1] का memeber city सेलेक्ट होगा |
a-.>city को हम a[0]. भी लिख सकते है |
उदहारण के लिए
#include<conio.h>
#include<stdio.h>
Struct book
{
Char book_name [20];
Int publish_year ;
Char author [20];
Int price;
} bok[2],b;
Void main ()
{
Printf(“data”);
For (b=bok;b<bok+3;b++)
{
Scnaf(“%s %d %s %d”,bok->book_name,bok->publish_year,bok->author,bok->price);
}
Printf(“Output Data”);
For (b=bok;b<bok+3;b++)
{
printf(“Book name:%s ,Publish Year:%d ,Author name:%s ,Price:%d”,bok->book_name,bok->publish_year,bok->author,bok->price);
}
getch();
}
इस उदहारण मे ,दो
record सेव होगे इसलिय इसमें structure data type ‘book’ के दो variable का array
को use करता है |जैसे
जब pointer variable की value bok [0] का address होगा tab record 1 मे data read होगा |
after increment ,pointer variable मे bok[1] का address होगा तब
record 2 मे data read होगा |
आउटपुट होगा
Data
The fire wings 2008 Abdul kalam 230
The half girlfriend 2009 Cheten Bhagat 250
Output
Book name :The fire wings, Publish Year:2008 Author name: Abdul
kalam Price:230
Book name :The half girlfriend, Publish Year:2009 Author name:Chaten
Bhagat Price:250

Sorting Program
जब किसी array के element को sort किया जाता है तब उस प्रोग्रम को pointer से easily handle हो सकता  है |
source code
#include<conio.h>
#include<stdio.h>
void sort(int ,int *);’
void main()
{
int i;
int size=8;
int d[8]={12,56,23,45,76,65,96,32};
sort (size,a);
printf(“Sorted Array “);
for(i=0;i<8;i++)
{
printf(“%d”,d[i]);
}
getch();
}
void sort (int n,int *a)
{
int e,f,t;
for(e=1;e<=n-1;e++)
{
for(f=1;f<n-1;f+
{
if(*(a+f-1)>=*(a+f))
{
t=*(a+f-1);
*(a+f-1)=*(a+f);
*(a+f)=t;
}
}

इस प्रोग्रम मे array को function argument मे pass करते है |और pointer variable ‘a’ मे receive कर देते है |comparison और swapping प्रोसेस मे pointer variable की value को use किया है जो की array element के address है |

आउटपुट होगा :
Sorted Array
96 76 65 56 45 32 23 12

Sbistudy

Recent Posts

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

2 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks 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