C Data Types

Understand different data types in C with practical examples.

C में विभिन्न data types को आसान उदाहरणों के साथ समझें।

Data types in C define the type of data a variable can store — like integers, decimals, or characters.

C में data types यह निर्धारित करते हैं कि कोई variable किस प्रकार का डेटा store कर सकता है — जैसे कि integer, decimal या character।


Example 1: Integer (int)

#include <stdio.h>

int main() {
    int num = 100;
    printf("Integer: %d", num);
    return 0;
}

`int` stores whole numbers.

`int` पूरे (integer) numbers को store करता है।

Output: Integer: 100


Example 2: Float (float)

#include <stdio.h>

int main() {
    float pi = 3.14;
    printf("Float: %.2f", pi);
    return 0;
}

`float` stores decimal numbers.

`float` दशमलव संख्या को store करता है।

Output: Float: 3.14


Example 3: Double (double)

#include <stdio.h>

int main() {
    double val = 3.1415926535;
    printf("Double: %.10lf", val);
    return 0;
}

`double` stores more precise decimal numbers.

`double` अधिक precision वाले decimal numbers को store करता है।

Output: Double: 3.1415926535


Example 4: Character (char)

#include <stdio.h>

int main() {
    char grade = 'A';
    printf("Character: %c", grade);
    return 0;
}

`char` stores single characters.

`char` एक character को store करता है।

Output: Character: A


Example 5: Short int

#include <stdio.h>

int main() {
    short int a = 32767;
    printf("Short int: %d", a);
    return 0;
}

`short int` is a smaller integer type.

`short int` छोटा integer data type होता है।

Output: Short int: 32767


Example 6: Long int

#include <stdio.h>

int main() {
    long int b = 2147483647;
    printf("Long int: %ld", b);
    return 0;
}

`long int` stores larger integer values.

`long int` बड़े integer मानों को store करता है।

Output: Long int: 2147483647


Example 7: Unsigned int

#include <stdio.h>

int main() {
    unsigned int c = 40000;
    printf("Unsigned int: %u", c);
    return 0;
}

`unsigned int` stores only positive integers.

`unsigned int` केवल positive integers को store करता है।

Output: Unsigned int: 40000


Example 8: Size of data types

#include <stdio.h>

int main() {
    printf("Size of int: %lu bytes", sizeof(int));
    return 0;
}

`sizeof()` shows the memory size of a data type.

`sizeof()` एक data type की memory size दिखाता है।

Output: Size of int: 4 bytes


Example 9: Using multiple types

#include <stdio.h>

int main() {
    int a = 5;
    float b = 2.5;
    printf("Sum: %.2f", a + b);
    return 0;
}

C allows mixing `int` and `float` in expressions.

C में `int` और `float` को mix करके expression में use किया जा सकता है।

Output: Sum: 7.50


Example 10: Constant float

#include <stdio.h>

int main() {
    const float PI = 3.14;
    printf("PI: %.2f", PI);
    return 0;
}

`const` prevents changes to variable value.

`const` का प्रयोग fixed value रखने के लिए होता है।

Output: PI: 3.14