Basic Data Types in C
In C programming, data types are declarations for variables. They determine the type and size of data associated with a variable. Basically, there are four commonly used data types in C programming. They include; int, double, float and char.
If you’re new to programming, the idea of data types might seem confusing. But don’t worry! In this article, we’ll go through the basics of each type of data in C programming.
Get Daniel Mbedobe K.’s stories in your inbox
Join Medium for free to get updates from this writer.
Check out the video tutorial on youtube below:
int
int is a signed integer. ints are small enough to store whole numbers, it can hold up to 32 bits of information, which is enough for storing most whole numbers (positive or negative).
int width = 12;Here int is the data type of the variable width.
float and double
You’ll probably want to use float or double when storing numbers with decimal places. Both are single-precision floating point numbers, which means that they can represent a number with more than 23 digits after the decimal place (the number is said to be “rounded”). The advantage of using float is that it can contain more information about the original value than double does, but both are equivalent in terms of accuracy and precision, though doubles are more precise with their storage.
float size = 12.6;
double mark = 23.45;Char
The char keyword is used to declare character-type variables in C programming. A char is a single character. Character data types store one value at a time in memory; they can hold any ASCII value from 0–127 (or 128), but can’t store other characters such as newline or tab.
char hist = 'w';Notice the use of single quotes around the value.
Size of Data Types
In order to find the size of each data type in C programming, we can use the built-in sizeof operator to find the amount of storage required for each.
#include <stdio.h>
int main ()
{
//find the size of a data type
printf("int: %ld byte(s)\n", sizeof(int));
printf("double: %ld byte(s)\n", sizeof(double));
printf("float: %ld byte(s)\n", sizeof(float));
printf("char: %ld byte(s)\n", sizeof(char));
}I hope this article was helpful to you! Remember, if you’re still not sure about any of the information I covered here, feel free to reach out to me in the comments at any time. I’ll be happy to explain anything further or help with any questions that may arise from reading this post.









