What is Datatype?
Data type is used for declaring the type of a variable. The type of variable determines how much size will it occupie in storage. C support three classes of data types:
- Primary data type.
- Derived data type.
- User-defined data type.
Primary data types that are available in C are:
int is used to define Integer variables. The size of integer data type is 2 bytes or 16 bits. The range for signed integer is -32,768 to 32,767.
Integer variable can be declared as follows:
int val = 23;
char is used to define Integer variables. The size of char data type is 1 byte or 8 bits. The ASCII range of character is -128 to 127.
float is used to define Integer variables. The size of float data type is 4 bytes or 32 bits. The range of float is 3.4E-38 to 3.4E+38.
f = 2.6;
double is used to define Integer variables. The size of double data type is 8 bytes or 64 bits. The range is 1.7E-308 to 1.7E+308.
d = 3.14;
The void type has no values. This is used to define the return type of function. The function with void return type does not return any value to the calling function.
Derived Data type includes following :
User-Defined Type Declaration:
A User definied data is a data type that derived from an existing primitive data type. It is used to create customized data type when the name of data type become long or slightly complicated. “Typedef” is used to create user defined data type.
typedef int chirag;
typedef float sachin;
Here chirag symbolize “int” and sachin symbolize “float”.
chirag and sachin can be further used as a data type.
name1,name2 is used as “int” variable.
v1,v2 is used as “float” variable.
Size and range of datatype:
Datatypes, their Keywords and format specifiers:
Some characters are not the part of characters set. An Escape sequence is a sequence of characters that does not represent itself when used inside a string literal.
All escape sequences consist of two characters:
- The first of which is the backslash, \ (called the "Escape character")
- the remaining characters determine the interpretation of the escape sequence.