Home >Backend Development >C++ >What are the different types of data in C language?
A data type is a memory location or declaration of a variable. Data can be of different types. Examples of data types in C language are as follows:
Integers, rational numbers, integers, real numbers, complex numbers, vectors, characters, etc.
For machines In hardware terms, data is encoded as a sequence of binary bits 0 and 1. In the machine, integer data is processed in the Arithmetic Logic Unit (ALU) and fractional data is processed in the Floating Point Unit (FPU). This is reflected in the built-in or primitive data types of high-level languages.
There are different built-in data types in C language, some of them are as follows:
Int, float, char, unsigned int, unsigned char, long Int, double, etc.
In C language, you can use different types to store data in different ways. Here are some examples:
In the above example, char, int, and float are built-in data types, while string and grade are variables of type char.
#Grade=’A’ initializes the variable grade to the character code of the character ‘A’.
Count and index are variables of type int.
And index=10 initializes the variable to 10 in binary representation.
The following is a C program to find the size of variables and built-in data types:
Live Demo
#include<stdio.h> int main(){ int x = 10; char c; printf("Size of variable x = %ld bytes</p><p>",sizeof(x)); printf("Size of variable c = %ld byte</p><p>",sizeof(c)); printf("Size of short is %ld bytes</p><p>",sizeof(short)); printf("Size of int is %ld bytes</p><p>",sizeof(int)); printf("Size of long is %ld bytes</p><p>",sizeof(long)); printf("Size of float is %ld bytes</p><p>",sizeof(float)); printf("Size of double is %ld bytes</p><p>",sizeof(double)); printf("Size of long double is %ld bytes</p><p>",sizeof(long double)); printf("Size of char is %ld bytes</p><p>",sizeof(char)); printf("Size of void is %ld bytes</p><p>",sizeof(void)); return 0; }
When the above program is executed, the following results are produced-
Size of variable x = 4 bytes Size of variable c = 1 byte Size of short is 2 bytes Size of int is 4 bytes Size of long is 4 bytes Size of float is 4 bytes Size of double is 8 bytes Size of long double is 16 bytes Size of char is 1 bytes Size of void is 1 bytes
The above is the detailed content of What are the different types of data in C language?. For more information, please follow other related articles on the PHP Chinese website!