Do you want to learn C programming from scratch? Then you are at right place. In this post, data types and their sizes in C programming will be discussed in detail.
In C programming, before using any variable, the programmer has to declare the data type it is going to hold in it.
For example, if a variable is going to store a value which is integer then before using it, its data type has to be set as int. eg: int value;
Here value is the name of the variable which can be anything whereas, int define the data type it is going to hold. Thus, in the example, variable ‘value’ can store integer value.
Program to assign various data types
Example program to assign various data types in C programming
#include <stdio.h>
void main()
{
char a = ‘S’;
short b = 123;
short c = -123;
int d = 1600;
int e = -1600;
long f = 12345;
long g = -12345;
float h = 10.552;
float i = -10.552;
double j = 11.1234567890;
return;
}
Data types in C programming
Broadly speaking, there are four basic data types in C programming. They are
- char
- int
- float
- double
char
char data type in C programming is used to store one character. Its size is a byte.
Example: char c= ‘u’;
Here c is a variable of char type that stores character ‘u’ and its size is one byte or 8 bits.
int
This data type is used to store integer. Its size can be either two or four bytes that depend on size of the integer on the machine where the program is running.
Example: int n= 5;
In this example, n is a variable of integer type and stores the value 5.
Below is the program to find the exact size of the integer data type in C programming on your mach ine. It also give the maximum and minimum number that can be stored in integer data type on your computer.