top of page

Datatypes - Primitive datatypes C (Integer, Char, float, double, long, long double and void)

  • Writer: Siddharth Sharma
    Siddharth Sharma
  • Oct 6, 2025
  • 4 min read

What are Primitive Data Types? / मूल प्रकार क्या हैं?

  • Primitive (primary/built-in) वो types हैं जो language में directly मौजूद होते हैं: int, char, float, double, long (as a length modifier), long double, void.

  • In practice, you combine base types with modifiers: signed/unsigned, short/long.

Quick Compiler Reality Check

  • Size depends on platform/ABI. Typical on LP64 (Linux/macOS 64-bit): int=4B, long=8B, long long=8B. On Windows 64-bit (LLP64): int=4B, long=4B, long long=8B. Use code: printf("%zu", sizeof(int)); to verify.



  • 1. Integer Family / पूर्णांक प्रकार

  • Purpose: Whole numbers without decimal.

  • Base keyword: int. Modifiers: signed, unsigned, short, long.

  • Typical sizes (common compilers):

    • short: 2 bytes, range signed: −32,768…32,767; unsigned: 0…65,535

    • int: 4 bytes, range signed: −2,147,483,648…2,147,483,647; unsigned: 0…4,294,967,295

    • long: 4 bytes (Windows) or 8 bytes (Linux/macOS 64-bit)

    • long long: 8 bytes (signed: −9.22e18…+9.22e18 approx)

  • Format specifiers (printf/scanf):

    • int: %d / %i (unsigned %u)

    • short: %hd (unsigned %hu)

    • long: %ld (unsigned %lu)

    • long long: %lld (unsigned %llu)

  • Examples:

int a = 42;              // %d
unsigned int u = 300U;   // %u
long L = 1234567890L;    // %ld
long long LL = 900000000000LL; // %lld
  • Tips:

    • Counting/indexing: prefer int unless you truly need larger range.

    • For bit-precision, use stdint.h types: int32_t, uint64_t.


    2. Character Type / अक्षर प्रकार (char)

  • Purpose: Single byte character or small integer.

  • Size: 1 byte. Three variants: char, signed char, unsigned char (char’s signedness is implementation-defined).

  • Ranges: signed char −128…127, unsigned char 0…255.

  • Specifier: %c for character I/O; for numeric printing cast to int and use %d.

  • Examples:

char ch = 'A';         // %c prints A
unsigned char b = 255; // print numeric: printf("%u", (unsigned)b);
  • Note: char is also used for C-strings as arrays terminated by '\0'.

  • Floating-Point Types / दशमलव संख्या प्रकार

  • Purpose: Real numbers with fractional part (IEEE-754 typical).

  • float: 4 bytes, ~6–7 decimal digits precision, range ≈ 1.2e−38 to 3.4e+38. Specifier: %f (printf), %f (scanf).

  • double: 8 bytes, ~15–16 digits precision, range ≈ 2.3e−308 to 1.7e+308. Specifier: %lf (printf accepts %f too), %lf (scanf).

  • long double: 80-bit (x87) or 128-bit (some platforms) or same as double (on MSVC). Specifier: %Lf (printf), %Lf (scanf).

  • Examples:

float f = 3.141593f;           // %f
double d = 2.718281828459045;  // %lf
long double ld = 1.2345L;      // %Lf

  • Tips:

    • For precise decimal (money), prefer integer cents or fixed-point; floats can round.

    • Use <float.h> for FLT_DIG, DBL_MAX etc.


4.void Type / रिक्त प्रकार

  • Meaning: “no value/no type”.


  • Uses:

    • Function return type when nothing returns: void func(void);

    • Function parameter list as void means no parameters in old-style, but in prototypes use (void) to mean zero parameters.

    • void* generic pointer: can point to any object type; must cast to proper type before dereference.

  • Not allowed: variables of type void (except void* pointers).


    5. long and long double Clarified

  • long is a length modifier applied to integer base types: long int, long long int, unsigned long, etc.

  • long double is a distinct floating type with higher precision than double on many but not all platforms.


Cheat Table (Typical, but verify with sizeof)

Data Type

Size (Bytes)

Format Specifier

Usage / Example

हिंदी विवरण

int

4

%d / %u

int x = 10;

पूरा अंक स्टोर करता है

short

2

%hd / %hu

short s = 5;

छोटा पूरा अंक

long

4 or 8

%ld / %lu

long l = 99999L;

बड़ा पूरा अंक

long long

8

%lld / %llu

long long ll = ...;

बहुत बड़ा पूरा अंक

char

1

%c

char ch = 'A';

एक अक्षर स्टोर करता है

float

4

%f

float f = 2.5F;

दशमलव संख्या

double

8

%lf

double d = 3.14;

अधिक सटीक दशमलव संख्या

long double

8, 10, 12, 16

%Lf

long double ld = ...;

सबसे ज़्यादा सटीकता

void

0

N/A

void func();

कोई वैल्यू नहीं, खाली

  • int: Whole numbers like पूरा अंक

  • short: Smaller whole number छोटा पूरा अंक

  • long: Larger whole number बड़ा पूरा अंक

  • long long: Very large integer बहुत बड़ा पूरा अंक

  • char: Single character एक अक्षर

  • float: Decimal numbers (approx 7 digit precision) दशमलव संख्या

  • double: More precise decimal (approx 15 digit precision) अधिक सटीक दशमलव संख्या

  • long double: Highest precision decimals सबसे ज़्यादा सटीकता

  • void: No value, just type for empty functions or generic pointers कोई वैल्यू नहीं



Common Pitfalls / सावधानियाँ

  • Mismatch specifiers: printing double with %f in printf is okay (double promotes), but scanf needs %lf for double.

  • Overflow: assigning large literal to int may overflow; use suffixes: 1234567890L, 100ULL.

  • Signedness of char: compare against unsigned ranges carefully.

  • Platform differences: long size varies; avoid assuming long is 4B.


Mini Practice (try mentally):

  1. Which specifier for unsigned long long? Answer you expect: %llu.

  2. Will this compile? printf("%d", sizeof(int)); Why/why not? Hint: sizeof returns size_t; %zu is correct; %d may warn.

  3. If you need exactly 64-bit unsigned, which type to pick? Hint: <stdint.h>.

Tiny Code to Inspect Sizes


c
#include <stdio.h>
#include <stdint.h>
#include <float.h>
int main(void){
  printf("char %zu\n", sizeof(char));
  printf("short %zu\n", sizeof(short));
  printf("int %zu\n", sizeof(int));
  printf("long %zu\n", sizeof(long));
  printf("long long %zu\n", sizeof(long long));
  printf("float %zu\n", sizeof(float));
  printf("double %zu\n", sizeof(double));
  printf("long double %zu\n", sizeof(long double));
  return 0;
}

Quick Recap / सार

  • Primitive types define storage and operations at the lowest level.

  • Choose the narrowest type that safely fits your data and matches your I/O specifiers.

  • Verify sizes on your platform; don’t hardcode assumptions.

 
 
 

Comments


bottom of page