हेलो दोस्तों !
आज की इस Most important function of stdlib.h header file in C language in Hindi पोस्ट में हम stdlib.h header file के most important फंक्शन को बारे में जानेंगे। तो दोस्तों अगर आप stdlib.h हैडर फाइल के सबसे useful फंक्शन को जानना चाहते है तो इस पोस्ट को अंत तक जरूर पढ़े।
इस पोस्ट के मुख्य टॉपिक्स :-
- stdlib.h header file क्या है ?
- important function of stdlib.h header file.
1. stdlib.h header file क्या है :-
तो दोस्तों stdlib.h हैडर फाइल के important फंक्शन को जानने से पहले हम यह जान लेते है की stdlib.h हैडर फाइल क्या होती है ?
दोस्तों जैसा की आपको पता होगा की हैडर फाइल एक विशेष फाइल होती है जिनमें काफ़ी सारे फंक्शन डिक्लेअर होते है। या कहे तो उस हैडर फाइल के अंडर में आते है। जिसका मतलब है की अगर हमें उस हैडर फाइल के किसी भी फंक्शन को अपने प्रोग्राम में यूज़ करना है तो आपको उस हैडर फाइल को अपने C प्रोग्राम में include करना पड़ेगा।
तो दोस्तों stdlib.h हैडर फाइल भी इसी तरह की एक हैडर फाइल है जिसमें काफ़ी सारे फंक्शन डिक्लेअर होते है। दोस्तों इस हैडर फाइल को standard library हैडर फाइल भी कहते है। ये stdlib.h हैडर फाइल में standard यूटिलिटी फंक्शन डिक्लेअर होते है इस हैडर फाइल में कई तरह के फंक्शन डिक्लेअर होते है जैसे मेमोरी एलोकेशन से रिलेटेड फंक्शन ,कुछ मैथ से रिलेटेड फंक्शन भी होते है।
दोस्तों अगर हम चाहें तो यह भी कह सकते है की जो फंक्शन किसी दूसरी हैडर फाइल फिट नहीं बैठते है। वो फंक्शन इस हैडर फाइल में होते है। फिट बैठने का मतलब है की उस हैडर फाइल के दूसरे सभी फंक्शन से बिल्कुल अलग होना। इस हैडर फाइल में काफ़ी इंटरेस्टिंग फंक्शन होते है। जो काफी इम्पोर्टेन्ट वर्क करते है।
2. important function of stdlib.h header file :-
तो दोस्तों stdlib.h हैडर फाइल के बारे में जानने के बाद अब हम इस हैडर फाइल के उन फंक्शन्स को जान लेते है जो सबसे ज्यादा useful होते है।
- atoi()
- atof()
- atol()
- exit()
- rand()
- abs()
- malloc()
- calloc()
- realloc()
- free()
दोस्तों इन फंक्शन को जानने के बाद अब हम इन फंक्शन को थोड़ा और विस्तार से जान लेते है।
1.atoi() :-
दोस्तों atoi फंक्शन stdlib.h हैडर फाइल का एक महत्वपूर्ण फंक्शन माना जाता है। क्योंकि इसकी मदद से हम स्ट्रिंग को integer में कन्वर्ट कर पाते है। तो अगर हम सिंपल शब्दो में कहे तो atoi फंक्शन एक ऐसा फंक्शन है जो स्ट्रिंग को integer में कन्वर्ट करता है।
syntax :-
int atoi(string_name);
Example program :-
#include< stdio.h >
#include< stdlib.h >
void main()
{
int intvalue,sum;
char str[20]="123456";
printf("This is numbers string:%s\n",str);
intvalue=atoi(str);
printf("String is converted in int:%d\n",intvalue);
sum=intvalue+1;
printf("Sum is:%d\n",sum);
}
program output :-
This numbers string : 123456
String is converted in int : 123456
Sum is : 123457
2.atof() :-
दोस्तों atoi फंक्शन की तरह ही atof फंक्शन भी एक useful फंक्शन होता है। अक्सर जब भी हमें किसी स्ट्रिंग को float में या double में कन्वर्ट करने की जरुरत होती है तो हम इस फंक्शन का यूज़ करते है। atof फंक्शन किसी स्ट्रिंग को float या double में कन्वर्ट करने का काम करता है।
syntax :-
float atof(string_name);
Example program :-
#include< stdio.h >
#include< stdlib.h >
void main()
{
float a;
double b;
char str[10]={"12345678"};
a=atof(str);
b=atof(str);
printf("a=%f\n",a);
printf("b=%f\n",b);
}
program output :-
a=12345678.000000
b=12345678.000000
3.atol() :-
दोस्तों atoi और atof फंक्शन की तरह ही atol फंक्शन भी एक जरुरी फंक्शन होता है। दोस्तों atol फंक्शन स्ट्रिंग को long इन्टिजर में कन्वर्ट करने के लिए यूज़ किया जाता है। इसलिए जब भी हमें स्ट्रिंग को long इन्टिजर में कन्वर्ट करने की जरुरत पड़ती है तो हम atol फंक्शन का ही यूज़ करते है।
syntax :-
long int atol(string_name);
Example program :-
#include< stdio.h >
#include< stdlib.h >
void main()
{
long int a;
char str[10]={"12345678"};
a=atol(str);
printf("a=%ld\n",a);
}
program output :-
a=12345678
4.exit() :-
दोस्तों exit फंक्शन के नाम से ही पता चलता है की यह exit करने का काम करता है। तो हा दोस्तों यह फंक्शन प्रोग्राम के execution को एग्जिट करने का ही काम करता है। दोस्तों यह फंक्शन अभी तक बताये गए फंक्शन से काफी ज्यादा यूज़ किया जाता है। इसलिए यह काफी important फंक्शन है।
syntax :-
void exit(int status);
Example program :-
#include < stdio.h >
#include < stdlib.h >
void main()
{
int a;
while (1)
{
printf("Enter 0 to exit program :");
scanf("%d", &a);
if (a == 0)
{
exit(0);
}
else
{
printf("You enter this number : %d\n", a);
}
}
}
program output :-
Enter 0 to exit program : 5
You enter this number : 5
Enter 0 to exit program : 10
You enter this number : 10
Enter 0 to exit program : 0
5.rand() :-
दोस्तों rand फंक्शन भी एक इम्पोर्टेन्ट फंक्शन माना जाता है। इसकी मदद से हम रैंडम नंबर को generate करते है। इसका मतलब है की जब भी हमें रैंडम नंबर generate करने की जरुरत पड़ती है तो हम इसी फंक्शन का यूज़ करते है।
syntax :-
int rand();
Example program :-
#include< stdlib.h >
#include< stdio.h >
void main()
{
for (int i = 0; i < 5; i++)
{
printf("Randam value is :- %d\n",rand());
}
}
program output :-
Randam value is :- 41
Randam value is :- 18467
Randam value is :- 6334
Randam value is :- 26500
Randam value is :- 19169
6.abs() :-
दोस्तों बाकि सभी फंक्शन की तरह ये भी stdlib.h हैडर फाइल का एक महत्वपूर्ण फंक्शन माना जाता है। abs फंक्शन absolute वैल्यू को return करता है। इसका मतलब है की अगर हमारे पास कोई नेगेटिव वैल्यू है तो हम उस वैल्यू को abs फंक्शन को पास करके पॉजिटिव वैल्यू में कन्वर्ट करा सकते है क्योंकि absolute वैल्यू हमेशा पॉजिटिव होती है।
syntax :-
int abs(value);
Example program :-
#include< stdio.h >
#include< stdlib.h >
void main()
{
int a;
int b;
a=abs(-500);
b=abs(-100);
printf("a=%d\n",a);
printf("b=%d\n",b);
}
program output :-
a=500
b=100
7.malloc() :-
दोस्तों C प्रोग्रामिंग में मेमोरी एलोकेशन का कांसेप्ट है जिसको हैंडल करने के लिए कुछ फंक्शन है और वो सभी फंक्शन इसी हैडर फाइल के अंडर आते है। उनमें से एक है malloc फंक्शन इस फंक्शन की मदद से हम dynamically मेमोरी को allocate करा सकते है। जब हमें dynamically मेमोरी allocate करने की जरुरत पड़ती है तो हम malloc फंक्शन का यूज़ करते है।
syntax :-
ptr=(cast type*)malloc(size);
example program :-
#include< stdio.h >
#include< stdlib.h >
void main()
{
printf("\n***Use of malloc function***\n");
int *a,*b,*c;
a=(int *)malloc(sizeof(int));
b=(int *)malloc(sizeof(int));
c=(int *)malloc(sizeof(int));
printf("Enter first number:");
scanf("%d",&*a);
printf("Enter second number:");
scanf("%d",&*b);
*c=*a+*b;
printf("sum of a and b is:%d\n",*c);
}
program output :-
***Use of malloc function***
Enter first number:5
Enter second number:4
sum of a and b is:9
8.calloc() :-
दोस्तों malloc फंक्शन की तरह calloc फंक्शन भी dynamically मेमोरी को allocate कराने के लिए यूज़ किया जाता है। लेकिन इस दोनों में कुछ अन्तर होता है calloc फंक्शन एक ही साइज के कई मेमोरी ब्लॉक को allocate करने के लिए किया जाता है जबकि malloc एक ही मेमोरी ब्लॉक को allocate करने के लिए यूज़ किया जाता है। calloc का यूज़ ज्यादातर डायनामिक ऐरे बनाने के लिए किया जाता है।
syntax :-
ptr=(type cast *) calloc(number of element,size);
Example program :-
#include< stdio.h >
#include< stdlib.h >
void main()
{
int *temp,*ptr;
printf("\n***Use of calloc function***\n");
ptr=(int *)calloc(5,2);
for(int i=0;i < 5;i++)
{
printf("Enter the number %d:",i);
scanf("%d",&*ptr+i);
}
for(int j=0;j < 5;j++)
{
temp=ptr+j;
printf("%d\t",*temp);
}
}
program output :-
***Use of calloc function***
Enter the number 0:5
Enter the number 1:4
Enter the number 2:3
Enter the number 3:2
Enter the number 4:6
5 4 3 2 6
9.realloc() :-
दोस्तों realloc फंक्शन भी डायनामिक मेमोरी को allocate करने के लिए यूज़ किया जाता है। लेकिन यह फंक्शन पहले से allocated मेमोरी को दुबारा allocate करने के लिए यूज़ किया जाता है। क्योंकि हमें कभी -कभी और ज्यादा bytes की जरूरत होती है तो हम उसी allocated मेमोरी साइज बढ़ाकर reallocate करा देते है।
syntax :-
ptr=realloc(ptr,new_size);
Example program :-
#include< stdio.h >
#include< stdlib.h >
void main()
{
int *ptr,*ptr1;
printf("\n***Use of realloc function***\n");
ptr=(int *)malloc(sizeof(2));
printf("Enter the long number:");
scanf("%d",&*ptr);
printf("\nThis number you enter:%d\n",*ptr);
ptr1=(int *)realloc(ptr,4);
printf("Enter the long number:");
scanf("%d",&*ptr1);
printf("\nThis number you enter:%d\n",*ptr1);
}
program output :-
***Use of realloc function***
Enter the long number:1234
This number you enter:1234
Enter the long number:453453
This number you enter:453453
10.free() :-
दोस्तों डायनामिक मेमोरी एलोकेशन में free एक महत्वपूर्ण फंक्शन होता है। क्योंकि जितनी भी मेमोरी हम dynamically allocate करते है तो वो मेमोरी तब तक फ्री नहीं होती है जब तक की हम उसे खुद फ्री न करे या जब तक प्रोग्राम end न हो। तो दोस्तों जो मेमोरी हम malloc ,calloc फंक्शन की मदद से dynamically allocate करते है उसी मेमोरी को फ्री करने के लिए free फंक्शन का यूज़ किया जाता है।
syntax :-
free(ptr);
Example program :-
#include< stdio.h >
#include< stdlib.h >
void main()
{
int *ptr;
printf("\n***Use of realloc function***\n");
ptr=(int *)malloc(sizeof(2));
printf("Enter the long number:");
scanf("%d",&*ptr);
printf("\nThis number you enter:%d\n",*ptr);
free(ptr);
printf("Memory is released\n");
printf("After memory released ptr value:%d",ptr);
}
program output :-
***Use of realloc function***
Enter the long number:535234
This number you enter:535234
Memory is released
After memory released ptr value:6894096
दोस्तों वैसे तो stdlib.h हैडर फाइल में और भी बहुत सारे फंक्शन है जो अपने आप में महत्वपूर्ण है। लेकिन हमने यहाँ केवल उन्ही फंक्शन्स के बारे में चर्चा की है जो काफी ज्यादा यूज़ किये जाते है।
Author :- तो दोस्तों हम आशा करते है की आपको हमारी यह Most important function of stdlib.h header file in C language in Hindi पोस्ट जरूर पसंद आई होगी। तो आज के लिए बस इतना ही फिर मिलेंगे ऐसी ही किसी और इंटरेस्टिंग पोस्ट में तब तक के लिए अलविदा !
0 Comments
Do not enter any spam comments please.