Data Types in C Language
A data type specifies the type of value that a variable can store. It determines the representation of data, the operations that can be performed on it, and the memory requirements of an object. C language provides different data types to store integer values, floating-point values, characters and other kinds of data. C language supports basic data types, derived data types, enumeration types and the void type. Programmers can also create their own data types using structures, unions and type definitions.
Data Type का उपयोग किसी Variable में संग्रहित किए जाने वाले मान (Value) के प्रकार को निर्धारित करने के लिए किया जाता है। यह Data के Representation, उस पर किए जा सकने वाले Operations तथा किसी Object के लिए आवश्यक Memory को निर्धारित करता है। C लैंग्वेज में Integer, Floating-Point, Character तथा अन्य प्रकार के Data को संग्रहित करने के लिए अलग-अलग Data Types उपलब्ध हैं। C लैंग्वेज में Basic Data Types, Derived Data Types, Enumeration Types तथा Void Type उपलब्ध हैं। प्रोग्रामर Structure, Union और Type Definitions की सहायता से भी अपने Data Types तैयार कर सकते हैं।
Classification of Data Types in C
C language data types can be classified into the following categories:
C लैंग्वेज के Data Types को निम्नलिखित श्रेणियों में विभाजित किया जा सकता है:
Basic or Fundamental Data Types
Derived Data Types
User-Defined and Enumeration Types
Void Data Type
1. Basic or Fundamental Data Types
Basic data types are the fundamental data types provided by the C language. They are used to store simple values such as integers, characters and floating-point numbers.
Basic Data Types वे मूलभूत Data Types होते हैं जो C लैंग्वेज द्वारा उपलब्ध कराए जाते हैं। इनका उपयोग Integer, Character और Floating-Point Numbers जैसे सामान्य मानों को संग्रहित करने के लिए किया जाता है।
C language provides the following basic data types:
C लैंग्वेज में निम्नलिखित Basic Data Types उपलब्ध हैं:
charintfloatdouble_Bool(introduced in C99)
A. Character Data Type (char)
The char data type is used to store a single character. It generally occupies one byte of memory. A character value is written inside single quotation marks.
char Data Type का उपयोग एक Character को संग्रहित करने के लिए किया जाता है। यह सामान्यतः Memory का एक Byte लेता है। Character Value को Single Quotation Marks के अंदर लिखा जाता है।
Example:
char grade = 'A';char ch = 'X';
B. Integer Data Type (int)
The int data type is used to store whole numbers without a fractional part. Integer data types are available in different forms, such as short int, int and long int. They can also be declared as signed or unsigned.
int Data Type का उपयोग बिना दशमलव वाले पूर्णांकों को संग्रहित करने के लिए किया जाता है। Integer Data Type के विभिन्न रूप होते हैं, जैसे short int, int और long int। इन्हें signed या unsigned के रूप में भी घोषित किया जा सकता है।
Example:
int age = 25;short int number = 100;long int population = 500000L;unsigned int count = 250;Common Integer Data Type Modifiers
C language provides type modifiers to change the range and representation of integer data types. Common modifiers are
short,long,signedandunsigned.C लैंग्वेज में Integer Data Types की Range और Representation को प्रभावित करने के लिए Type Modifiers उपलब्ध हैं। सामान्य Modifiers
short,long,signedऔरunsignedहैं।
Data Type Description short intShort integer type intInteger type long intLong integer type long long intExtended integer type signed intInteger that can represent negative and positive values unsigned intInteger that represents non-negative values The exact size and range of these data types depend on the compiler and platform. For example,intis not guaranteed to occupy exactly 2 or 4 bytes on every system.इन Data Types का वास्तविक Size और Range Compiler तथा Platform पर निर्भर करती है। उदाहरण के लिए, प्रत्येक System में
intका Size निश्चित रूप से 2 या 4 Bytes होना आवश्यक नहीं है।
C. Floating-Point Data Types (float and double)
Floating-point data types are used to store numbers that may contain fractional parts. C provides three commonly used floating-point types: float, double and long double. They differ in their minimum precision and implementation-defined representation.
Floating-Point Data Types का उपयोग ऐसी संख्याओं को संग्रहित करने के लिए किया जाता है जिनमें दशमलव भाग हो सकता है। C लैंग्वेज में सामान्यतः तीन Floating-Point Types उपलब्ध हैं: float, double और long double। इनकी Precision और Representation अलग-अलग हो सकती है।
Example:
float percentage = 85.5f;double salary = 45678.75;long double value = 12345.6789L;
D. Boolean Data Type (_Bool)
The _Bool data type was introduced in C99. It is used to store Boolean values, which are either 0 or 1. The header file stdbool.h provides the convenient names bool, true and false in C99 and later standards.
_Bool Data Type को C99 Standard में जोड़ा गया था। इसका उपयोग Boolean Values को संग्रहित करने के लिए किया जाता है, जिनका मान 0 या 1 होता है। C99 और उसके बाद के Standards में stdbool.h Header File के माध्यम से bool, true और false नामों का उपयोग भी किया जा सकता है।
Example:
#include <stdbool.h>bool isPassed = true;
2. Derived Data Types
Derived data types are formed using other data types. They allow programmers to work with collections of values, memory addresses and functions. The commonly discussed derived types in C are:
Derived Data Types का निर्माण अन्य Data Types की सहायता से किया जाता है। इनके द्वारा Programmer कई Values के समूह, Memory Addresses तथा Functions के साथ कार्य कर सकते हैं। C लैंग्वेज में सामान्यतः निम्नलिखित Derived Types का अध्ययन किया जाता है:
Array
Pointer
Function
A. Array
An array is a collection of elements of the same data type stored in contiguous memory locations. Each element is accessed using its index.
Array एक ही Data Type के Elements का समूह होता है, जो Memory में लगातार Locations पर संग्रहित होते हैं। इसके प्रत्येक Element को Index की सहायता से Access किया जाता है।
Example:
int marks[5] = {75, 80, 85, 90, 95};B. Pointer
A pointer is a variable that stores the memory address of another object or function, depending on its type. Pointers are useful for dynamic memory allocation, arrays and function arguments.
Pointer एक ऐसा Variable होता है जो किसी अन्य Object या Function का Memory Address संग्रहित करता है। Pointers का उपयोग Dynamic Memory Allocation, Arrays तथा Function Arguments में किया जाता है।
Example:
int number = 10;int *ptr = &number;
C. Function
A function is a block of code designed to perform a particular task. In C, function types are determined by their return type and parameter types.
Function किसी विशेष कार्य को करने के लिए बनाया गया Code Block होता है। C लैंग्वेज में Function का Type उसके Return Type और Parameters के Types के आधार पर निर्धारित होता है।
Example:
int add(int a, int b){return a + b;}
3. User-Defined and Enumeration Types
C language allows programmers to define new types using structures, unions and enumerations. These types help organize and represent related data.
C लैंग्वेज में Programmer को Structure, Union और Enumeration की सहायता से नए Types परिभाषित करने की सुविधा मिलती है। इनका उपयोग संबंधित Data को व्यवस्थित करने और Represent करने के लिए किया जाता है।
A. Structure (struct)
A structure is a user-defined data type that groups variables of different data types under a single name.
Structure एक User-Defined Data Type है, जिसके अंतर्गत अलग-अलग Data Types के Variables को एक ही नाम के अंतर्गत समूहित किया जा सकता है।
Example:
struct Student{int rollNo;char grade;float percentage;};
B. Union (union)
A union is a user-defined data type in which all members share the same memory location. The size of a union is sufficient to hold its largest member, subject to alignment requirements.
Union एक User-Defined Data Type है जिसमें इसके सभी Members एक ही Memory Location को साझा करते हैं। Union का Size सामान्यतः इसके सबसे बड़े Member को संग्रहित करने के लिए पर्याप्त होता है, जिसमें Alignment Requirements भी शामिल होती हैं।
Example:
union Data{int number;float price;char grade;};
C. Enumeration (enum)
An enumeration is a user-defined type that consists of a set of named integer constants. It makes programs easier to read and understand.
Enumeration एक User-Defined Type है जिसमें Named Integer Constants का एक समूह होता है। इसके उपयोग से प्रोग्राम को पढ़ना और समझना आसान हो जाता है।
Example:
enum Week{MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY};
4. Void Data Type
The void data type represents the absence of a value. It is commonly used when a function does not return any value. It is also used to declare generic pointers using void *.
void Data Type किसी Value की अनुपस्थिति को दर्शाता है। इसका उपयोग सामान्यतः ऐसे Function को घोषित करने के लिए किया जाता है जो कोई Value Return नहीं करता है। इसके अतिरिक्त void * का उपयोग Generic Pointer घोषित करने के लिए भी किया जाता है।
Example 1: Function returning no value
#include <stdio.h>void display(void){printf("Welcome to C Programming");}int main(void){display();return 0;}
Output:
Welcome to C ProgrammingExample 2: Generic pointer
int number = 10;void *ptr = &number;
Important: A variable cannot be declared using plain void. Therefore, void a; is invalid in standard C.
महत्वपूर्ण: केवल void का उपयोग करके Variable घोषित नहीं किया जा सकता। इसलिए void a; Standard C में Invalid है।
Program to Find the Size of Data Types in C
The sizeof operator is used to determine the memory size of a data type or object in bytes. Its result has the type size_t, which can be displayed using %zu.
sizeof Operator का उपयोग किसी Data Type या Object का Memory Size Bytes में ज्ञात करने के लिए किया जाता है। इसका Result size_t Type का होता है, जिसे %zu Format Specifier द्वारा Display किया जा सकता है।
C Program:
#include <stdio.h>int main(void){printf("Size of char = %zu byte(s)\n", sizeof(char));printf("Size of int = %zu byte(s)\n", sizeof(int));printf("Size of float = %zu byte(s)\n", sizeof(float));printf("Size of double = %zu byte(s)\n", sizeof(double));printf("Size of long double = %zu byte(s)\n", sizeof(long double));return 0;}
Sample Output:
Size of char = 1 byte(s)Size of int = 4 byte(s)Size of float = 4 byte(s)Size of double = 8 byte(s)Size of long double = 16 byte(s)
The output shown above is only an example. Actual sizes may differ depending on the compiler and system. sizeof(char) is always 1 by definition, although one C byte is not necessarily 8 bits.
ऊपर दिया गया Output केवल एक उदाहरण है। वास्तविक Size Compiler और System के अनुसार अलग-अलग हो सकता है। C Standard के अनुसार sizeof(char) हमेशा 1 होता है, हालांकि C का एक Byte आवश्यक नहीं कि 8 Bits का ही हो।
Common Format Specifiers for C Data Types
Format specifiers are used with input and output functions such as printf() and scanf() to read or display values of different data types.
printf() और scanf() जैसे Input तथा Output Functions में अलग-अलग Data Types के मानों को पढ़ने या Display करने के लिए Format Specifiers का उपयोग किया जाता है।
| Data Type | printf() Format | scanf() Format |
|---|---|---|
char | %c | %c |
int | %d or %i | %d or %i |
unsigned int | %u | %u |
short int | %hd | %hd |
long int | %ld | %ld |
long long int | %lld | %lld |
float | %f | %f |
double | %f | %lf |
long double | %Lf | %Lf |
String (char array) | %s | %s |
In printf(), a float argument is promoted to double, so %f is used for both float and double. In scanf(), %f is used for float *, while %lf is used for double *.
printf() में float Argument स्वतः double में Promote हो जाता है, इसलिए float और double दोनों के लिए %f का उपयोग किया जाता है। लेकिन scanf() में float * के लिए %f तथा double * के लिए %lf का उपयोग किया जाता है।
Data types are an essential part of C programming. They help programmers select suitable types for storing and processing different kinds of data. Understanding basic, derived, user-defined and void types is important for writing correct and efficient C programs.
Data Types, C Programming का एक महत्वपूर्ण भाग हैं। इनके द्वारा Programmer अलग-अलग प्रकार के Data को संग्रहित और Process करने के लिए उपयुक्त Type का चयन कर सकते हैं। सही और Efficient C Programs लिखने के लिए Basic, Derived, User-Defined तथा Void Types को समझना आवश्यक है.

Comments
Post a Comment