Void Data Type

The void data type in C is used to specify that no value is present. It does not provide a result value to its caller. It has no values and no operations. It is used to represent nothing. Void is used in multiple ways as function return type, function arguments as void, and pointers to void.

Syntax:

// function return type void
void exit(int check);
// Function without any parameter can accept void.
int print(void);
// memory allocation function which
// returns a pointer to void.
void *malloc (size_t size);

Example of Void

C




// C program to demonstrate
// use of void pointers
#include <stdio.h>
 
int main()
{
    int val = 30;
    void* ptr = &val;
    printf("%d", *(int*)ptr);
    return 0;
}


Output

30

Data Types in C

Each variable in C has an associated data type. It specifies the type of data that the variable can store like integer, character, floating, double, etc. Each data type requires different amounts of memory and has some specific operations which can be performed over it. The data type is a collection of data with values having fixed values, meaning as well as its characteristics.

The data types in C can be classified as follows:

Types

Description

Primitive Data Types Primitive data types are the most basic data types that are used for representing simple values such as integers, float, characters, etc.
User Defined Data Types The user-defined data types are defined by the user himself.
Derived Types The data types that are derived from the primitive or built-in datatypes are referred to as Derived Data Types.

Different data types also have different ranges up to which they can store numbers. These ranges may vary from compiler to compiler. Below is a list of ranges along with the memory requirement and format specifiers on the 32-bit GCC compiler.

Data Type 
 
Size (bytes) 
 
Range
 
Format Specifier 
 
short int 
 

 
-32,768 to 32,767 
 
%hd 
 
unsigned short int 
 

 
0 to 65,535 
 
%hu 
 
unsigned int 
 

 
0 to 4,294,967,295 
 
%u 
 
int 
 

 
-2,147,483,648 to 2,147,483,647 
 
%d 
 
long int 
 

 
-2,147,483,648 to 2,147,483,647 
 
%ld 
 
unsigned long int 
 

 
0 to 4,294,967,295 
 
%lu 
 
long long int 
 

 
-(2^63) to (2^63)-1 
 
%lld 
 
unsigned long long int 
 

 
0 to 18,446,744,073,709,551,615 
 
%llu 
 
signed char 
 

 
-128 to 127 
 
%c 
 
unsigned char 
 

 
0 to 255 
 
%c 
 
float 
 

 
1.2E-38 to 3.4E+38 %f 
 
double 
 

 
1.7E-308 to 1.7E+308 %lf 
 
long double 
 
16 
 
3.4E-4932 to 1.1E+4932 %Lf 
 

Note: The long, short, signed and unsigned are datatype modifier that can be used with some primitive data types to change the size or length of the datatype.

The following are some main primitive data types in C:

Similar Reads

Integer Data Type

The integer datatype in C is used to store the integer numbers(any number including positive, negative and zero without decimal part). Octal values, hexadecimal values, and decimal values can be stored in int data type in C....

Character Data Type

...

Float Data Type

Character data type allows its variable to store only a single character. The size of the character is 1 byte. It is the most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers....

Double Data Type

...

Void Data Type

In C programming float data type is used to store floating-point values. Float in C is used to store decimal and exponential values. It is used to store decimal numbers (numbers with floating point values) with single precision....

Size of Data Types in C

...