Difference between float and double
Generally the size of float(Single precision float data type) is 4 bytes and that of double(Double precision float data type) is 8 bytes. Floating point variables has a precision of 6 digits whereas the the precision of double is 14 digits.
Note: Precision describes the number of significant decimal places that a floating values carries.
Character types
Keyword char is used for declaring the variable of character type. For example:
char var4='h';
Here, var4 is a variable of type character which is storing a character 'h'.
The size of char is 1 byte. The character data type consists of ASCII characters. Each character is given a specific value. For example:
For, 'a', value =97
For, 'b', value=98
For, 'A', value=65
For, '&', value=33
For, '2', value=49
Here is the list of all ASCII characters in C language.
Qualifiers
Qualifiers alters the meaning of base data types to yield a new data type.
Size qualifiers:
Size qualifiers alters the size of basic data type. The keywords long and short are two size qualifiers. For example:
long int i;
The size of int is either 2 bytes or 4 bytes but, when long keywords is used, that variable will be either 4 bytes of 8 bytes. Learn more about long keyword in C programming. If the larger size of variable is not needed then, short keyword can be used in similar manner as long keyword.
Sign qualifiers:
Whether a variable can hold only positive value or both values is specified by sign qualifiers. Keywords signed and unsigned are used for sign qualifiers.
unsigned int a;
// unsigned variable can hold zero and positive values only
It is not necessary to define variable using keyword signed because, a variable is signed by default. Sign qualifiers can be applied to only int and char data types. For a int variable of size 4 bytes it can hold data from -231 to 231-1 but, if that variable is defined unsigned, it can hold data from 0 to 232 -1.
data type
Generally the size of float(Single precision float data type) is 4 bytes and that of double(Double precision float data type) is 8 bytes. Floating point variables has a precision of 6 digits whereas the the precision of double is 14 digits.
Note: Precision describes the number of significant decimal places that a floating values carries.
Character types
Keyword char is used for declaring the variable of character type. For example:
char var4='h';
Here, var4 is a variable of type character which is storing a character 'h'.
The size of char is 1 byte. The character data type consists of ASCII characters. Each character is given a specific value. For example:
For, 'a', value =97
For, 'b', value=98
For, 'A', value=65
For, '&', value=33
For, '2', value=49
Here is the list of all ASCII characters in C language.
Qualifiers
Qualifiers alters the meaning of base data types to yield a new data type.
Size qualifiers:
Size qualifiers alters the size of basic data type. The keywords long and short are two size qualifiers. For example:
long int i;
The size of int is either 2 bytes or 4 bytes but, when long keywords is used, that variable will be either 4 bytes of 8 bytes. Learn more about long keyword in C programming. If the larger size of variable is not needed then, short keyword can be used in similar manner as long keyword.
Sign qualifiers:
Whether a variable can hold only positive value or both values is specified by sign qualifiers. Keywords signed and unsigned are used for sign qualifiers.
unsigned int a;
// unsigned variable can hold zero and positive values only
It is not necessary to define variable using keyword signed because, a variable is signed by default. Sign qualifiers can be applied to only int and char data types. For a int variable of size 4 bytes it can hold data from -231 to 231-1 but, if that variable is defined unsigned, it can hold data from 0 to 232 -1.
data type
No comments:
Post a Comment