Data Types in C
Data Types in C
Data Types in C
Last Updated : 28 Sep, 2023
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.
Types Description
Primitive Data Primitive data types are the most basic data types that are used for
Types representing simple values such as integers, float, characters, etc.
User Defined
The user-defined data types are defined by the user himself.
Data Types
The data types that are derived from the primitive or built-in datatypes are
Derived Types
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
https://www.geeksforgeeks.org/data-types-in-c/?ref=next_article 1/11
5/12/24, 9:54 PM Data Types in C - GeeksforGeeks
-2,147,483,648 to
int 4 %d
2,147,483,647
-2,147,483,648 to
long int 4 %ld
2,147,483,647
https://www.geeksforgeeks.org/data-types-in-c/?ref=next_article 2/11
5/12/24, 9:54 PM Data Types in C - GeeksforGeeks
float 4 %f
1.2E-38 to 3.4E+38
double 8 %lf
1.7E-308 to 1.7E+308
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.
https://www.geeksforgeeks.org/data-types-in-c/?ref=next_article 3/11
5/12/24, 9:54 PM Data Types in C - GeeksforGeeks
Syntax of Integer
int var_name;
1. unsigned int: Unsigned int data type in C is used to store the data values from zero to
positive numbers but it can’t store negative values like signed int.
2. short int: It is lesser in size than the int by 2 bytes so can only store values from -32,768 to
32,767.
3. long int: Larger version of the int datatype so can store values greater than int.
4. unsigned short int: Similar in relationship with short int as unsigned int with int.
Note: The size of an integer data type is compiler-dependent. We can use sizeof
operator to check the actual size of any data type.
Example of int
int main()
{
// Integer value with positive data.
int a = 9;
https://www.geeksforgeeks.org/data-types-in-c/?ref=next_article 4/11
5/12/24, 9:54 PM Data Types in C - GeeksforGeeks
return 0;
}
Output
Syntax of char
https://www.geeksforgeeks.org/data-types-in-c/?ref=next_article 5/11
5/12/24, 9:54 PM Data Types in C - GeeksforGeeks
char var_name;
Example of char
int main()
{
char a = 'a';
char c;
a++;
printf("Value of a after increment is: %c\n", a);
return 0;
}
Output
Value of a: a
Value of a after increment is: b
https://www.geeksforgeeks.org/data-types-in-c/?ref=next_article 6/11
5/12/24, 9:54 PM Data Types in C - GeeksforGeeks
Value of c: c
Syntax of float
float var_name;
Example of Float
int main()
{
float a = 9.0f;
float b = 2.5f;
// 2x10^-4
float c = 2E-4f;
printf("%f\n", a);
printf("%f\n", b);
printf("%f", c);
https://www.geeksforgeeks.org/data-types-in-c/?ref=next_article 7/11
5/12/24, 9:54 PM Data Types in C - GeeksforGeeks
return 0;
}
Output
9.000000
2.500000
0.000200
The double data type is basically a precision sort of data type that is capable of holding 64 bits of
decimal numbers or floating points. Since double has more precision as compared to that float
then it is much more obvious that it occupies twice the memory occupied by the floating-point
type. It can easily accommodate about 16 to 17 digits after or before a decimal point.
Syntax of Double
The variable can be declared as double precision floating point using the double keyword:
double var_name;
Example of Double
https://www.geeksforgeeks.org/data-types-in-c/?ref=next_article 8/11
5/12/24, 9:54 PM Data Types in C - GeeksforGeeks
// C Program to demonstrate
// use of double data type
#include <stdio.h>
int main()
{
double a = 123123123.00;
double b = 12.293123;
double c = 2312312312.123123;
printf("%lf\n", a);
printf("%lf\n", b);
printf("%lf", c);
return 0;
}
Output
123123123.000000
12.293123
2312312312.123123
Syntax:
https://www.geeksforgeeks.org/data-types-in-c/?ref=next_article 9/11
5/12/24, 9:54 PM Data Types in C - GeeksforGeeks
Example of Void
// 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
https://www.geeksforgeeks.org/data-types-in-c/?ref=next_article 10/11
5/12/24, 9:54 PM Data Types in C - GeeksforGeeks
The size of the data types in C is dependent on the size of the architecture, so we cannot define
the universal size of the data types. For that, the C language provides the sizeof() operator to
check the size of the data types.
Example
int main()
{
int size_of_int = sizeof(int);
int size_of_char = sizeof(char);
int size_of_float = sizeof(float);
int size_of_double = sizeof(double);
return 0;
}
https://www.geeksforgeeks.org/data-types-in-c/?ref=next_article 11/11