JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: C Language in hindi

C99- Feature : array ,function और pointer related modification in c language in hindi

C99 में अर्रे , फंक्शन तथा पॉइंटर सम्बंधित परिवर्तन क्या है , C99- Feature : array ,function और pointer related modification in c language in hindi :-
C99- Feature ( Part -1 ) मे हमने नए variable , keywords और declartion of variable को पढ़ा |अब इस article मे array , function और pointer related modification  को पढ़गे |1.handling of array
C language मे , array के subscript को integer से initial करते है जिससे array की size fixed हो जाती है |लेकिन C 99 मे हम किसी भी expression को array के subscript को initial करते है |इन variable की value vary हो सकते है | अतः जब इन variable को run time पर declare किया जाता है तब array की  size change हो सकता है |
इसका उदाहरण है :
#include<stdio.h>
#include<conio.h>
void main()
{
int a[n];
int n;
printf(“Enter Size of array “);
scanf(“%d”,&n);
printf(“Entyer Elements”);
int(int i=0;i<n;i++)
{
scanf(“%d”,a[i]);
}
int(int i=0;i<n;i++)
{
printf(“Array [%d] = %d”,i,a[i]);
}
getch();
}

इस उदहारण मे , variable ‘n’ को declare किया गया है |और यूजर से ‘n’ की value input करते है |और इसे array के सुन्स्क्रिप्त मे pass करते है |
इसका उदाहरण है :-
Enter Size of array 3
Entyer Elements 23 343 45
Array [0] = 23
Array [1] = 343
Array [2] = 45

और
Enter Size of array 5
Entyer Elements 23 343 45 56 67
Array [0] = 23
Array [1] = 343
Array [2] = 45

Array [3] = 56

Array [4] = 67

2.Type Specification in array declaration
जब हम किसी array को function argument मे pass करते है तब array के dimension मे static keyword का use किया जाता है |static keyword यहा declare करता है की array मे fixed size के element होने चाहिए |
#include<stdio.h>
#include<conio.h>
int avg (int a [ ]);
void main()
{
int a[10];
printf(“Enter Elements”);
int(int i=0;i<10;i++)
{
scanf(“%d”,a[i]);
}
int avg = avg (a[static 5);
printf(“Average of array element = %d”,avg);
getch();
}
int avg (b[static 5)
{
int sum ;
for (int i=0;i<5;i++)
{
sum = sum + b[i];
}
int avg = sum / 5;
return(avg );
}

इस उदाहरण मे , static 5 का मतलब है की array a के सिर्फ 5 elements हो function avg () मे pass होगे |
आउटपुट होगा :
Enter Elements  23 34 45 56 67 56 56 67 78 89
Average of array element = 45


Flexible Array 
जब हम किसी structure में array को declare करते है तब C 99 मे , flexible array को declare किया जाता है |
flexible array का मतलब है एसी array जिसकी size define ना हो |flexible array को use कर्ण एके लिए कुछ rules होते है :-
1.flexible array structure की last member होते है |
2.flexible array के dimension सेक्शन मे कोई भी value नहीं होती है |
3.structure flexible array के अलावा दुसरे भी member होने चाहिए |
flexible array से dynamic memory allocation :
जब किसी structure से dynamic memory allocation किया जाता है |तब इसकी size को calculate किया जाता है |जैसे
struct student{
int age;
int class;
int grade;
char name [ ]; // flexible variable
};
इस structure के लिए ,
int age: age एक integer type data है जिसका size 4 bytes है |
int class : class एक integer type data है जिसका size 4 bytes है |
int grade : grade एक integer type data है जिसका size 4 bytes है |
char name [ ] : char name [ ] एक flexible array है जिसका size 0 bytes है |
Total size = 4+4+4+0 = 12 bytes

जब किसी flexible array से sturuture को declare किया जाता है तब  इसका syntax है :-
struct student *s1 = malloc(sizeof(*s1)+sizeof(char[strlen(name)]);
यहा पर :
*s1 : ये pointer variable है जिसमे allocate memory के address को point करता है |
sizeof(*s1): ये structure student की size को calculate करता है लेकिन flexible array की size को ‘0’ consider करता है |
sizeof(char[strlen(name)]) : ये structure मे declare flexible array की size को calculate करता है |

अगर flexible array की size 6 है  तब sizeof(char[strlen (name)])  की value 6 bytes होगी |


उदाहरण के लिए :
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int create_structure(struct student *stu , int a , int c , char n[ ]);
void print_structure (struct student *stu);
struct student{
int age;
int class;
int size;            // this variable used for store size of structure student //
char name [ ]; // flexible variable //
};
void main()
{
struct student *stu1=create_structure(stu1,12,3,parth);
struct student *stu2=create_structure(stu2,13,3,om);
print_structure(stu1);
print_structure(stu2);
printf(“Size of structure student= %u \n”,sizeof(struct student));
getch();
}
int create_structure(struct student *stu , int a , int c , char n[ ])
{
stu=malloc(sizeof (*stu)+sizeof(char)*sizeof (name));
stu.age=a;
stu.class=c;
strcpy(stu.name , n);
stu.size= sizeof(*stu)+sizeof(char)*sizeof (name);
return(stu);
}
void print_structure (struct student *stu)
{
printf(“Age : %d\n
Class : %d \n
Name : %s \n \n”,
stu.age, stu.class, stu.name );
printf(“Size of structure =%d”,stu.size);
}

इस प्रोग्राम मे , तीन function को use किया गया है |
1.main() : इस function मे , यूजर से data लिया गया है जिसे बाकि के दो functions मे pass किया जाता है |लेकिन इस प्रोग्राम मे , हमने direct values को function मे pass किया गया है |
2.create_structure() : इस function का use , structure के लिए memory allocate करने के लिए किया जाता है |इसके अलावा main function मे से pass की गयी student details को pointer variable stu1 मे assign किया जाता है |
3.print_structure : इस function का use , structure के देतिअल्स को print करने के लिए किया जाता है |


आउटपुट होगा :
Age : 12
Class : 3
Name : parth
Size of structure =13

Age : 13
Class : 3
Name : om
Size of structure =10

Size of structure student= 8

Sbistudy

Recent Posts

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

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

23 hours ago

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

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

24 hours 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