Keyword char
is used for declaring character type variables. For example,
char test = 'h';
The size of the character variable is 1 byte.
http://learnhtml.foobrdigital.com/wp-content/uploads/2021/12/4080944.png
Keyword char
is used for declaring character type variables. For example,
char test = 'h';
The size of the character variable is 1 byte.
float
and double
are used to hold real numbers.
float salary;
double price;
In C, floating-point numbers can also be represented in exponential. For example,
float normalizationFactor = 22.442e2;
What’s the difference between float
and double
?
The size of float
(single precision float data type) is 4 bytes. And the size of double
(double precision float data type) is 8 bytes.
Integers are whole numbers that can have both zero, positive and negative values but no decimal values. For example, 0
, -5
, 10
We can use int
for declaring an integer variable.
int id;
Here, id is a variable of type integer.
You can declare multiple variables at once in C programming. For example,
int id, age;
The size of int
is usually 4 bytes (32 bits). And, it can take 232
distinct states from -2147483648
to 2147483647
.
There are the following data types in C language.
Types | Data Types |
---|---|
Basic Data Type | int, char, float, double |
Derived Data Type | array, pointer, structure, union |
Enumeration Data Type | enum |
Void Data Type | void |
The basic data types are integer-based and floating-point based. C language supports both signed and unsigned literals.
The memory size of the basic data types may change according to 32 or 64-bit operating system.
Let’s see the basic data types. Its size is given according to 32-bit architecture.
Data Types | Memory Size | Range |
---|---|---|
char | 1 byte | −128 to 127 |
signed char | 1 byte | −128 to 127 |
unsigned char | 1 byte | 0 to 255 |
short | 2 byte | −32,768 to 32,767 |
signed short | 2 byte | −32,768 to 32,767 |
unsigned short | 2 byte | 0 to 65,535 |
int | 2 byte | −32,768 to 32,767 |
signed int | 2 byte | −32,768 to 32,767 |
unsigned int | 2 byte | 0 to 65,535 |
short int | 2 byte | −32,768 to 32,767 |
signed short int | 2 byte | −32,768 to 32,767 |
unsigned short int | 2 byte | 0 to 65,535 |
long int | 4 byte | -2,147,483,648 to 2,147,483,647 |
signed long int | 4 byte | -2,147,483,648 to 2,147,483,647 |
unsigned long int | 4 byte | 0 to 4,294,967,295 |
float | 4 byte | |
double | 8 byte | |
long double | 10 byte |
As the name suggests, a Datatype defines the type of data being used. Whenever we define a variable or use any data in the C language program, we have to specify the type of the data, so that the compiler knows what type of data to expect.
For example, you may want to use a number like 1, 2, 100, or a decimal point number like 99.95, 10.5, or a text, like “Studytonight”, all these values are handled differently by the C language compiler, hence, we use data types to define the type of data used in any program.
Broadly, there are 5 different categories of data types in the C language, they are:
Type | Example |
---|---|
Basic | character, integer, floating-point, double. |
Derived | Array, structure, union, etc. |
Enumeration | enums |
Bool type | true or false |
void | Empty value |
The C language has 5 basic (primary or primitive) data types, they are:
There are different keywords to specify these data types, the keywords are:
Datatype | Keyword |
---|---|
Character | char |
Integer | int |
Floating-point | float |
Double | double |
Void | void |