In this tutorial, you’ll learn about data types and how to declare the variable in C programming.
In C programming, variables should be declared before it can be used. Similarly, the function also needs to be declared before use.
Data types simply refer to the type and size of the data associated with variables and functions.
The data type can be either fundamental (provided in C compiler) or derived (derived from fundamental data types).
Fundamental data types
This section focus on commonly used fundamental data types.
Integers are whole numbers, can have both zero, positive and negative values but no decimal values. Example: 0, -5, 10
You can use int for declaring an integer variable.
Here, nt is a variable of a type integer.
You can declare multiple variables once in C programming. For example:
The size of int is four bytes (32 bits) in most compilers. Hence, it can take 232 distinct state: -231,-231+1, …, -1, 0, 1, 2, …, 231-2, 231-1
, that’s, from -2147483648 to 2147483647
float and double
float and double are used to hold the real number.
In C program, 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 is 4 bytes. And the size of double is 8 bytes.