अंतिम बार 02/03/2023 को अपडेट किया गया।
डाटा टाइप (Data Type) - C-भाषा में किसी भी डाटा का उपयोग करने से पहले इनकी टाइप निर्धारित की जानी आवश्यक होती है, जिससे कम्प्यूटर की सीमित मैमोरी में उसे उचित स्थिति पर पर्याप्त स्थान दिया जा सके। डाटा के विभिन्न टाइप मैमोरी में भिन्न-भिन्न स्थान घेरते हैं। अतः डाटा के टाइपों का वर्गीकरण करके उनके लिए आवश्यक मैमोरी के स्थान का निर्धारण करना आवश्यक होता है।
C-भाषा में डाटा के दो टाइप प्रमुख होते हैं।
(क) इंटीजर और (ख) फ्लोटिंग पॉइंट। इन दो टाइपों के व्युत्पन्न अन्य दो प्रकार के होते हैं-(ग) करेक्टर और (घ) डबल। (ङ) वॉइड (Void) एक अन्य प्रकार का डाटा होता है जिसका उपयोग अत्यन्त कम होता है।
There are four basic data types in C programming, namely Char, Int, Float, and Double.
int = For integer Value
float = For Decimal Value
char = For Characters Value
double = For Double Value
Integer Data Type :-
C में पूर्णांक डेटा प्रकार का उपयोग दशमलव मानों के बिना पूर्ण संख्याओं को संग्रहीत करने के लिए किया जाता है। ऑक्टल मान, हेक्साडेसिमल मान और दशमलव मान C में int डेटा प्रकार में संग्रहीत किए जा सकते हैं। हम C में sizeof ऑपरेटर का उपयोग करके int डेटा प्रकार का आकार निर्धारित कर सकते हैं। C में अहस्ताक्षरित int डेटा प्रकार का उपयोग डेटा मानों को संग्रहीत करने के लिए किया जाता है। शून्य से धनात्मक संख्याओं तक लेकिन यह हस्ताक्षरित int जैसे ऋणात्मक मानों को संग्रहीत नहीं कर सकता है। हस्ताक्षरित int की तुलना में अहस्ताक्षरित int आकार में बड़ा है और यह C प्रोग्रामिंग भाषा में एक प्रारूप विनिर्देशक के रूप में “%u” का उपयोग करता है। नीचे C में int डेटा प्रकार का प्रोग्रामिंग कार्यान्वयन है।
Syntax:-
int variable_name;
Example
The following example illustrates the int data types in C.
#include <stdio.h>
int main()
{
//variables num, ans and i
//are initialised as int
int num = 5, ans = 1;
int i;
printf("The multiples of num are: \n");
for (i = 1; i <= num; i++)
{
//int variable is getting multiplied
//with int and the result is
//stored in another int variable
ans = i * num;
//print the result
printf("5 * %d", i);
printf(" is %d",
ans);
printf("\n");
}
}
Character Data Type :-
कैरेक्टर टाइप कैरेक्टर डेटा टाइप अपने वेरिएबल को केवल एक ही कैरेक्टर को स्टोर करने की अनुमति देता है। कैरेक्टर का स्टोरेज साइज 1 है। यह C में सबसे बेसिक डेटा टाइप है। यह सिंगल कैरेक्टर स्टोर करता है और लगभग सभी कंपाइलर्स में सिंगल बाइट मेमोरी की जरूरत होती है।
Syntax:-
char variable_name;
Example
The following example illustrates the char data types in C.
#include <stdio.h>
int main()
{
//variable ch is initialised as char
char ch = 'A';
//storing same ASCII code in int
int num = ch;
//print the ASCII value of ch
printf("The ASCII code for %d", ch);
printf(" is %d", num);
printf("\n");
printf("Adding 1 to the character code \n");
//Adding 1 to the char variable ch
ch += 1;
//num stores the corresponding
//ASCII value of ch
num = ch;
//print the ASCII value of ch+1
printf("The ASCII code for %d", ch);
printf(" is %d", num);
}
Float Data Type :-
फ़्लोटिंग-प्वाइंट प्रकार C प्रोग्रामिंग में फ़्लोटिंग-पॉइंट मानों को संग्रहीत करने के लिए फ़्लोट डेटा प्रकार का उपयोग किया जाता है। C में फ़्लोट का उपयोग दशमलव और घातीय मानों को संग्रहीत करने के लिए किया जाता है। इसका उपयोग एकल परिशुद्धता के साथ दशमलव संख्याओं (फ्लोटिंग पॉइंट वैल्यू वाले नंबर) को स्टोर करने के लिए किया जाता है।
Syntax:-
float varaible_name;
Example
The following example illustrates the float data types in C.
#include <stdio.h>
int main()
{
//variable radius is initialised as float
float radius = 10.0;
//print the radius
printf("Radius of the circle is: %f", radius);
printf("\n");
//variable area is initialised as float
float area;
area = 3.14 * radius * radius;
//print the area of the circle
printf("Area of the circle is :%f", area);
}
Double Data Type :-
डबल प्रकार सी में एक डबल डेटा प्रकार का उपयोग दशमलव संख्या (फ्लोटिंग पॉइंट वैल्यू वाले नंबर) को डबल परिशुद्धता के साथ स्टोर करने के लिए किया जाता है। इसका उपयोग संख्यात्मक मानों को परिभाषित करने के लिए किया जाता है जो सी में दशमलव मानों के साथ संख्याएँ रखते हैं। डबल डेटा प्रकार मूल रूप से डेटा प्रकार का एक सटीक प्रकार है जो 64 बिट दशमलव संख्याओं या फ़्लोटिंग पॉइंट्स को रखने में सक्षम है। चूंकि उस फ्लोट की तुलना में डबल में अधिक सटीकता है, इसलिए यह अधिक स्पष्ट है कि यह फ़्लोटिंग-पॉइंट प्रकार के कब्जे में दो बार मेमोरी पर कब्जा कर लेता है। यह दशमलव बिंदु के बाद या उससे पहले लगभग 16 से 17 अंकों को आसानी से समायोजित कर सकता है।
Syntax:-
double variable_name;
Example
The following example illustrates the double data type in C.
#include <stdio.h>
// function to calculate surface area and volume
// of a sphere
void sphere(int radius)
{
// variables to hold double values
double surfaceArea, sphereVolume;
//Calculating the surface area
//and surface volume of the sphere
surfaceArea = 4 * 3.14 * radius * radius;
sphereVolume = (surfaceArea * radius) / 3;
printf("The surface area of the sphere is: %lf", surfaceArea);
printf("\n\nThe volume of the sphere is: %lf", sphereVolume);
}
int main()
{
int radius = 6;
sphere(radius);
printf("\n\n");
return 0;
}
Syntaint All Data Types:-
#include <stdio.h>
int main()
{
int num = 12;
printf("%d", num);
printf("\n");
float fl = 1.25;
printf("%f", fl);
printf("\n");
char ch = 'a';
printf("%c", ch);
printf("\n");
char name[] = "Abc";
printf("%s", name);
printf("\n");
}
Output :
12
1.250000
a
Abc