What are the Basic Datatypes in c Programming?
4 basic data types in c they are int, float, double, char.
Each and every datatypes in c provides differnt size which is efficient to hold that data in variable.
Different set of operation can be carried on different Data types in c which can hold different data.
After reading this article you will have a brief knowledge on Data types in c.
Data Types in c
Basic Data Types in c
- int
- float
- double
- char
- void
Enumeration Data Type in c
- enum
Derived Data Types
Derived data types are also called as “User defined datatypes”.
- pointer
- array
- structure
- union
Void Data Type
- void
Basic Data Types in c
int Datatype
In c int datatype can be used store integer variable.
‘ int ‘ is a keyword used to define a varibale which contains integer value.
example declaration of int : int value=10;
Now lets see the different variations of int type and their ranges.
Type | Memory (in Bytes) | Range | Format specifier |
short int | 2 | -32768 to 32767 | %hd |
unsigned short int | 2 | -32768 to 32767 | %hu |
unsigned int | 4 | 0 to 4294,967295 | %u |
int | 4 | -2147483648 to 2147483647 | %d |
long int | 8 | -2147483648 to 2147483647 | %ld |
unsigned long int | 8 | 0 to 4294967295 | %lu |
long long int | 8 | -(2^63) to (2^63)-1 | %lld |
unsigned long long int | 8 | 0 to 18446744073709551615 | %llu |
float Datatype
float data type in c is used to represent a variable which holds the decimal number of single precision.
‘ float ‘ is the keyword used to declare a float variable.
Example for float variable declaration in c : float pi=3.142
.
Type | Memory (in Bytes) | Range | Format specifier |
float | 4 | 1.2E-38 to 3.4E+38 | %lf |
double Datatype
double data type in c is used to represent a variable which holds the decimal nomber of double precision.
‘double’ is the keyword used to declare a double variable.
Type | Memory (in bytes) | Range | Format specifier |
double | 8 | 2.3E-308 to 1.7E+308 | %lf |
long double | 16 | 3.4E-4932 to 1.1E+4932 | %Lf |
char Datatype
char datatype in c is used to store a character.
In c each character has a unique asci code hence it is easy to convert from int to char and vice versa.
Char type is basic datatype of c.
‘char’ is the keyword used to declare a char type variable.
It takes one byte of memory space but range varies.
Type | Memory (in Bytes) | Range | Format specifies |
char | 1 | -128 to 127 or 0 to 255 | %c |
signed char | 1 | 0 to 255 | |
unsigned char | 1 | -128 to 127 |
#include<stdio.h>
int main(int argc, char const *argv[])
{
printf("\nC datatypes\nBasic Datatypes\n");
int number=10;//its integer type.
float fine=3.156;//its float type.
double pi=3.142;//its double type.
char c='x';//its char type.
//lets print their values.
printf("Number : %d\nfine : %f\npi : %lf \nc : %c\n",number,fine,pi,c);
return 0;
}

enumeration Data Types
Enumeration datatype in c is used to hold the integral contants.
‘enum’ is th ekeyword used to declare an enum.
example declaration: enum word{"hello","world" }
#include<stdio.h>
int main(int argc, char const *argv[])
{
printf("\nC datatypes\nDerived Datatypes\n");
enum week {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};//enum of week days
enum week today;
today = Saturday;
printf("Day %d\n",today+1);
return 0;
}

Derived Data Types
User defined datatypes are datatypes which are derived from basic data types. We can create our own data types using basic data types.
pointers
pointer variable holds/stores the address of another variable. You can declare a pointer by using * operator.
Ex: int *pointer;
In above example we are declaring a pointer which points to int type variable. Initially the poiter is null. You cal simply assign the address using & operator like below.
int *pointer
int number=10;
pointer=&number;
Read more about pointers here.
Array
c Arrays are continuous elements stored in continuous memory blocks.
Use [ size ] to declare an array.
Example: int array[10];
structure in c
This is a user defined data-type. By using structure programmer can easily group different other data type variables.
It stores element in different memory location for each of its members.
Dot ( . ) operator is used to access a structure variable.
Arrow operator is used to access structure variable via pointer.
‘struct
‘ is the keyword used to declare a structure.
Example:
struct my_struct
{
int data;
char c;
}
union in c
Union is a special user defined datatype. It is same as structure but stores element in same memory location.
‘union
‘ is the keyword to define a union.
Example:
union example
{
int t;
char c;
}
#include<stdio.h>
int main(int argc, char const *argv[])
{
printf("\nC datatypes\nDerived Datatypes\n");
struct example_struct//this is structure
{
int num;
};
struct example_struct e;
e.num=10;
union example_union//this is union
{
int data;
float pi;
};
union example_union un;
un.pi=3.142;
int array[2]={1,2};//this is array
int num=0;//this is int variable
int *ptr=#//pointer pointing to num
printf( " Struct variable: %d\nUnion Example: %f \nArray elements : %d %d\nPointer value %d\n",e.num,un.pi,array[0],array[1],*(ptr) );
return 0;
}

void datatype in c
void in c is an empty data-type which has no value.
void is mainly used in return value of a function and in pointers.
#include <stdio.h>
void example()
{
printf("Void Datatype Example\n");
}
int main(int argc, char const *argv[])
{
printf("\nDatatype in c\n");
example();
return 0;
}

People also ask
How to use character in c language
Declare a variable of character datatype. You can assign a character or you can take input from stdin. Then you can perform various operations on that character.
Example: char c='c';
What is %d in C called?
%d is a format specifier for int data type in c programming.
What are the user defined data types in C?
User defined datatypes are created using basic datatypes in other words user dedfined datatypes are derived from basic data types.
What are the 4 data types?
4 Basic datatypes are int ,float, double, char
Is enum a user defined data type?
Enum is a user defined datatype. It is considered as enumeration dataype.
Is array a user defined data type?
Yes aray is user defined datatype. It can be of any basic datatypes.
What is the real data type?
Real datatype is a datatype used to represent real numbers. But c doesnt have real keyword to represent a real number.
which datatype has more precision?
Double datatype has more precision in c programming language.