Data type ye decide karta hai ki variable ke andar kis type ka data store hoga aur kitni memory use hogi. Ye C programming ka sabse important concept hota hai.
Data Type = Type of Data + Memory Size
1. Data Type
Jab hum C mein variable declare karte hain, to compiler ko batana padta hai ki:
- Variable kis type ka data store karega
- Kitni memory reserve hogi
- Variable par kaun‑kaun se operations perform ho sakte hai.
Example:
int age = 19;
Yahan int compiler ko batata hai ki age ek integer value store karega.
2. Types of Data Types in C
C programming mein mainly 4 types ke data types hote hain:
- Basic (Primitive) Data Types
- Derived Data Types
- User‑Defined Data Types
- Void Data Type
1. Basic (Primitive) Data Types
Basic data types wo hote hain jo directly data store karte hain.
(i) int
int ka use whole numbers store karne ke liye hota hai.
int numbers = 100;
- Memory: Ye 2 bytes occupy karta hai 32-bit system mein aur 4 bytes occupy karta hai 64-bit system mein.
- Range: -32,768 se 32,767 (2 bytes system) and -2,147,483,648 se 2,147,483,647 (4 bytes system).
(ii) float
float ka use decimal values store karne ke liye hota hai.
float price = 99.50;
- Memory: 4 bytes
- Precision: 6 decimal digits tak
(iii) double
double bhi decimal values ke liye hota hai, lekin ye float se zyada accurate hota hai.
double pi = 3.1415926535;
- Memory: 8 bytes
- Precision: 15 decimal digits tak
(iv) char
char ka use single character store karne ke liye hota hai.
char grade = 'A';
- Memory: 1 byte
- Character single quotes
' 'mein likha jata hai
2. Derived Data Types
Derived data types basic data types se milkar bante hai.
(i) Array
Array ek hi type ki multiple values store karta hai.
int marks[5] = {80, 85, 90, 75, 88};
(ii) Pointer
Pointer ek variable hota hai jo dusre variable ka address store karta hai. Ye memory management and advanced programming mein use hota hai.
int a = 10;
int *p = &a;
(iii) Function
Function bhi ek derived data type maana jata hai jo kisi specific task ko perform karta hai.
function add(int a, int b){
return a+b;
}
3. User-Defined Data Types
User-Defined Data Types ko ham khud create karte hai apni requirements ke according.
(i) struct
struct ka use different data types ko ek saath group karne ke liye hota hai.
struct Student {
int id;
char name[20];
float marks;
};
(ii) union
union bhi struct jaisa hi hota hai, lekin sab members same memory share karte hain. Ye memory efficient hota hai.
union Data {
int i;
float f;
};
(iii) enum
enum ka use named constants banane ke liye hota hai.
enum Days {Mon, Tue, Wed, Thu, Fri};
(iv) typedef
typedef existing data type ka nickname banata hai.
typedef unsigned int uint;
uint age = 25;
4. Void Data Type
void ka matlab hota hai no value.
Example:
void display() {
printf("Hello World");
}
Comments (0)
Please login to leave a comment.
No comments yet. Be the first to comment!