Tutorials Logic, IN +91 8092939553 info@tutorialslogic.com
FAQs Support
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Interview Questions Website Development
Compiler Tutorials

C Data Types

Primary Data Types

C provides several built-in data types. The size of each type may vary by platform, but the values below are typical for a 64-bit system.

TypeSizeFormat SpecifierRangeDescription
int4 bytes%d or %i-2,147,483,648 to 2,147,483,647Integer numbers
float4 bytes%f~3.4×10⁻³â¸ to 3.4×10³â¸Single-precision decimal
double8 bytes%lf~1.7×10⁻³â°â¸ to 1.7×10³â°â¸Double-precision decimal
char1 byte%c-128 to 127 (or 0 to 255)Single character
voidNo value (used for functions/pointers)

Type Modifiers

Type modifiers change the size or sign of a base type. They can be combined with int, char, and double.

TypeSizeFormat SpecifierRange
short int2 bytes%hd-32,768 to 32,767
unsigned int4 bytes%u0 to 4,294,967,295
long int4 or 8 bytes%ld-2,147,483,648 to 2,147,483,647 (min)
long long int8 bytes%lld-9.2×10¹⁸ to 9.2×10¹⁸
unsigned long long8 bytes%llu0 to 1.8×10¹⁹
unsigned char1 byte%c0 to 255
long double10 or 16 bytes%LfExtended precision

Derived Types

C also has derived data types that are built from primary types:

  • Arrays — collection of elements of the same type
  • Pointers — variables that store memory addresses
  • Structures — group of variables of different types under one name
  • Unions — similar to structures but share the same memory
  • Functions — blocks of reusable code
Declaring and Printing All Data Types
#include <stdio.h>

int main() {
    int    age    = 25;
    float  price  = 9.99f;
    double pi     = 3.14159265358979;
    char   grade  = 'A';

    printf("int:    %d\n",  age);
    printf("float:  %f\n",  price);
    printf("double: %lf\n", pi);
    printf("char:   %c\n",  grade);

    // Printing char as integer (ASCII value)
    printf("char as int: %d\n", grade);  // 65

    return 0;
}

/*
Output:
int:    25
float:  9.990000
double: 3.141593
char:   A
char as int: 65
*/
sizeof Operator and Type Modifiers
#include <stdio.h>

int main() {
    // sizeof returns the size in bytes
    printf("Size of char:           %zu bytes\n", sizeof(char));
    printf("Size of int:            %zu bytes\n", sizeof(int));
    printf("Size of float:          %zu bytes\n", sizeof(float));
    printf("Size of double:         %zu bytes\n", sizeof(double));
    printf("Size of long int:       %zu bytes\n", sizeof(long int));
    printf("Size of long long int:  %zu bytes\n", sizeof(long long int));
    printf("Size of unsigned int:   %zu bytes\n", sizeof(unsigned int));

    // Type modifiers in action
    unsigned int  population = 4294967295U;  // max unsigned int
    long long int bigNum     = 9223372036854775807LL;
    short int     small      = 32767;

    printf("\nunsigned int:   %u\n",   population);
    printf("long long int:  %lld\n",  bigNum);
    printf("short int:      %hd\n",   small);

    return 0;
}

/*
Output (64-bit system):
Size of char:           1 bytes
Size of int:            4 bytes
Size of float:          4 bytes
Size of double:         8 bytes
Size of long int:       8 bytes
Size of long long int:  8 bytes
Size of unsigned int:   4 bytes
*/

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.