Data types in C
For Complete YouTube Video: Click Here
In this class, we try to understand the Data types in C.
Let us take the previous programming example from the Introduction to C Programming class.
In the first line of the program, int a, b, c; declares that a, b, and c are variables, and int is the data type.
Data type in the declaration of the variable states the type of data the variable can store.
C Supports four basic data types.
- int
- float
- double
- char
The int data type is used to store integer values; a float data type is to keep decimal numbers [35.64], a double data type is to hold decimal numbers with more precision, and a char data type is to store a character.
Each data type has its size. The size of the data type is compiler or machine-dependent.
Based on the computer, the size of the data types is allocated by the compiler.
We consider a machine for which the compiler has allocated 4 Bytes for int, 4 Bytes of float, 8 Bytes for double, and 1 Byte for char.
Now consider the declaration int a = 14;.
The image below shows how decimal number 14 will be stored in the memory.
Now consider the char data type. The char data type is used to store a character.
The character data types are declared differently compared to int.
Whenever we declare character, we have to enclose it in single quotes.
char c = ‘a’;
We can convert a decimal number into a binary number. The converted binary number will get stored in memory.
How can a character data type be converted?
C compiler uses unique codes for every character. The ASCII standards provide the codes.
Search for the ASCII codes of all the characters.