Data Types in C. In this tutorial, we
will learn about data types and also learn how types of data types are and how
to declare variables in C programming? We Will Also Learn How To Declare
Variable In C Programming ? Improving start.
Data types in C
- Before using variable and function in C programming, it has to declare.
- The data type specifies the type and nature of the variable and function, what type of data they can store and how much memory will occupy, meaning that the data type specifies the type of any variable in how much this variable memory location The space will occupy and what type of data will it store.
Types of Data type in C
- Data types in C programming are of the following types which are given below but generally data types are of two types
*Basic data type and
derived data type*
- Basic data type
- Derived data type
- Enumerated type
- Void data type
Data
Types in C
Let us know about
all these in details in detail.
Basic Data Type
This data type is
the primary data type which represents the actual data in computer
memory, which means which variable will be of what size, how much memory will
occupy, they specify. Under the basic data type integer, floating-point
and char type come. Let's explain all about one by one.
Integer (int)
Integer
data type is used to store the whole number, it can store zero, negative
and positive values like 0, 3, 6, -7, -9, -120. It does not store data
type decimal number (decimal number) such as 1.2, -2.3.
To
declare the Integer variable int keyword
Is used. For example: int a;
Here a is a variable name which is a variable of integer
type. You can declare multiple variables in C programming. Comma is used to
separate multiple variables. like:
int a, b, c;
The range of int data
type is from -32768 to 32767 or -2147483648 to 2147483647. Its range varies
according to different operating systems. Like there is different range for
32-bit operating system and different range for 64-bit operating system.
You can use the
sizeof operator to know the size of any data type and variable on
different platforms i.e. different operating systems. sizeof describes the size
of your variable and data type in bytes.
The following program describes
how to find the size of int type. You can know the size of all data types
by sizeof.
#include
int main() {
printf("size of int type in bytes : %d
/n “, sizedof(int));
return 0;
}
When you compile and execute this program, this program
will give you the output according to the architecture of your operating
system.
My operating system is of 64-bit architecture so
it is providing 4 bytes
answer.
Size of int type in bytes: 4
In the table below, the size and range of integer
and character type are described.
Type
|
Storage Size
|
Range
|
char
|
1
byte
|
-128
to 127 or 0 to 255
|
unsigned
char
|
1
byte
|
0
to 255
|
signed
char
|
1
byte
|
-128
to 127
|
Int
|
2
bytes or 4 bytes
|
-32,768
to 32,767 or -2,147,483,648 to 2,147,483,647
|
unsigned
int
|
2
bytes or 4 bytes
|
0
to 65,535 or 0 to 4,294,967,295
|
short
|
2
bytes
|
-32,768
to 32,767
|
unsigned
short
|
2
bytes
|
0
to 65,535
|
long
|
4
bytes
|
-2,147,483,648
to 2,147,483,647
|
unsigned
long
|
4
bytes
|
0
to 4,294,967,295
|
Floating-point types
Floating-point
types are used to store real numbers such as 5.02, 5.364, -5.012 under this
type float, double and long double data types.
The size of the float data
type is 4 bytes, the size of the double data type is 8 bytes, while
the size of the long double data type is 10 bytes.
All three types store
different types of precision. Precision means digits after decimal.
The
table below provides the details of the type, range, storage size and precision
of the floating-point number.
Type
|
Storage Size
|
Range
|
Precision
|
float
|
4
bytes
|
1.2E-38
to 3.4E+38
|
6
decimal places
|
double
|
8
bytes
|
2.3E-308
to 1.7E+308
|
15
decimal places
|
long
double
|
10
bytes
|
3.4E-4932
to 1.1E+4932
|
19
decimal places
|
char
char
is used to store a single character. The single character is written within a
single quote. The char keyword is used to define a variable of character type.
The size of the character variable is 1 byte. Range from -128 to 127 or 0 to
255.
declaration
of character type variable:
char
first =’a’;
Derived data type in C
- Derived data type is used with the help of primary data type hence it is called derived data type. We Will Learn About All The Derived Data Types In Different Tutorials.
- Array type
- Pointer Type
- Structure type
- Union type
Void Data type in C
void data type does not return
any type of value, meaning it specifies no value available. When we do not have
to return any type of value from a function, we can specify the type of that
function void.
Always keep in mind that you cannot
declare the variable of type void.
Read also : operator in c
Read also :what is constant
Post a Comment
Please do not any spam link in the comment