Data Types in C language

 Data Types in C language

Data types are integer-based and floating-point-based. The memory is allocated by the operating system to variables and decides what can be stored in the reserved memory.

 

Types Description
Basic Types Basic types are arithmetic types and are classified into integer types and floating-point types.
Enumerated types Enumerated are used to define variables that can only assign integer values through the program.
The type void The type void means no value is available.
Derived types Derived types contain Pointer types,  Array types, Structure types, Union types, and Function types.

 

The following table shows the list of basic data types in C language:

Category Data Types
character char
Integer int
Floating Point float
Double Floating Point double
The Void Type void

 

The following table describes the variable type, memory size, format specifier, and maximum, minimum value which can be stored in the variable.

Data Type Memory (bytes) Range Format Specifier
short int 2 -32,768 to 32,767 %hd
unsigned short int 2 0 – 65,535 %hu
unsigned int 4 0 – 4,294, 967,295 %u
int 4 -2,147,483,648 – 2,147,483,647 %d
long int 4 -2,147,483,648 – 2,147,483,647 %ld
unsigned long int 4 0 – 4,294,967,295 %lu
long long int 8 – ( 263 ) – ( 263 ) -1 %lld
unsigned long long int 8 0 – 18,446,744,073,709,551,615 %llu
signed char 1 -128 – 127 %c
unsigned char 1 0 – 255 %c
float 4 %f
double 8 %lf
long double 16 %Lf

 

Sizeof() function in c language

The memory size of a data type is different as shown in the table. The function is used to find the size of a data type, sizeof().

Program

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

 

Output

Size of char: 1
Size of short: 2
Size of int: 4
Size of long: 8
Size of float: 4
Size of double: 8
Size of void: 1

 

The void Type in c language

The void type shows that no value is available.

Types Types & Description
Function returns as void There are various functions in C programming which do not return any value.

Example, void exit (int status);

Function arguments as void There are various functions in C programming which do not accept any parameter. A function with no parameter accepts void.

Example, int rand(void);

Pointers to void A pointer of type void * represents the address of an object, but not its type.

Example, void *malloc( size_t size ); 

 

Also read, C-Operators

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *