Data Type In C Programming Language






In C language, there are several data types available to represent different types of values. Here is a comprehensive list of the common data types in C:

Integers:

  • int - represents a signed integer (can be positive, negative or zero)
  • short - represents a short integer
  • long - represents a long integer
  • long long - represents a very long integer
  • unsigned int - represents an unsigned integer (only positive or zero)
  • unsigned short - represents an unsigned short integer
  • unsigned long - represents an unsigned long integer
  • unsigned long long - represents an unsigned very long integer

Floating-point numbers:

  • float - represents a single precision floating-point number
  • double - represents a double precision floating-point number
  • long double - represents a very high precision floating-point number

Characters:

  • char - represents a single character (such as a letter, digit or symbol)

Boolean:

_Bool or bool - represents a boolean value (either true or false)

Enumerated types:

enum - represents a set of named integer constants

Pointers:

  • void* - represents a generic pointer
  • int* - represents a pointer to an integer
  • char* - represents a pointer to a character

Arrays:

  • int[] - represents an array of integers
  • char[] - represents an array of characters

Structures:

  • struct - represents a collection of related variables of different data types

Unions:

  • union - represents a collection of variables that share the same memory location Each data type has its own range of values, size in memory, and operations that can be performed on it.


List of Data Type With Description, Size (bytes) and Range of Values


Data Type Description Size (bytes) Range of Values
int Represents a signed integer (can be positive, negative or zero) 2 or 4 -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
short Represents a short integer 2 -32,768 to 32,767
long Represents a long integer 4 or 8 -2,147,483,648 to 2,147,483,647 or -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
long long Represents a very long integer 8 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned int Represents an unsigned integer (only positive or zero) 2 or 4 0 to 65,535 or 0 to 4,294,967,295
unsigned short Represents an unsigned short integer 2 0 to 65,535
unsigned long Represents an unsigned long integer 4 or 8 0 to 4,294,967,295 or 0 to 18,446,744,073,709,551,615
unsigned long long Represents an unsigned very long integer 8 0 to 18,446,744,073,709,551,615
float Represents a floating point number 4 1.2E-38 to 3.4E+38
double Represents a double precision floating point number 8 2.3E-308 to 1.7E+308
long double Represents an extended precision floating point number 10 or 12 or 16 3.4E-4932 to 1.1E+4932 or 3.4E-4932 to 1.2E+4932 or 3.4E-4932 to 1.2E+4932
char Represents a single character 1 -128 to 127 or 0 to 255
unsigned char Represents an unsigned single character 1 0 to 255


Data Type Sizes


#include <stdio.h>

int main() {
    printf("Size of char: %9lu byte(s)\n", sizeof(char));
    printf("Size of short: %8lu byte(s)\n", sizeof(short));
    printf("Size of int: %10lu byte(s)\n", sizeof(int));
    printf("Size of long: %9lu byte(s)\n", sizeof(long));
    printf("Size of long long: %4lu byte(s)\n", sizeof(long long));
    printf("Size of float: %8lu byte(s)\n", sizeof(float));
    printf("Size of double: %7lu byte(s)\n", sizeof(double));
    printf("Size of long double: %3lu byte(s)\n", sizeof(long double));
    printf("Size of pointer: %6lu byte(s)\n", sizeof(void*));

    return 0;
}

Output:



Size of char:         1 byte(s)
Size of short:        2 byte(s)
Size of int:          4 byte(s)
Size of long:         4 byte(s)
Size of long long:    8 byte(s)
Size of float:        4 byte(s)
Size of double:       8 byte(s)
Size of long double:  16 byte(s)
Size of pointer:      8 byte(s)