Types
|
Data Types
|
Basic data types | int, char, float, double |
Enumeration data type | enum |
Derived data type | pointer, array, structure, union |
Void data type | void |
Here we will discuss only basic data types.
Each variable in C has an associated data type. Each data type requires different amounts of memory and has some specific operations which can be performed over it. Let us briefly describe them one by one:
It cannot cache the variables in register.
Data Type Memory(bytes) Range Format Specifier
short int 2 -32,768 to 32,767 %hd
unsigned short int 2 0 to 65,535 %hu
unsigned int 4 0 to 4,294,967,295 %u
int 4 -2,147,483,648 to 2,147,483,647 %d or %i
long int 4 -2,147,483,648 to 2,147,483,647 %ld
unsigned long int 4 0 to 4,294,967,295 %lu
long long int 8 -(2^63) to (2^63)-1 %lld
unsigned long long int 8 0 to 18,446,744,073,709,551,615 %llu
signed char 1 -128 to 127 %c
unsigned char 1 0 to 255 %c
float 4 3.4E-38 to 3.4E+38 %f
double 8 1.7E-308 to 1.7E-30 %lf
long double 12 3.4E-4932 to 1.1E+4932 %Lf
Data type- size in byte
char -1
short int -2
int -2
long int or long -4
float -4 (6 decimal places of precision)
double -8 (15 decimal places of precision)
long double -10 (19 decimal places of precision)
char 1 byte
short 2 bytes
int 4 bytes
long 4 bytes
float 4 bytes
double 8 bytes
long double 16 bytes
#include <stdio.h>
int main()
{
int a = 1;
char b ='G';
double c = 3.14;
//printing the variables defined above along with their sizes
printf("character. value is %c and size is %lu byte.\n",b,sizeof(char));
printf(" integer. value is %d and size is %lu bytes.\n", a,sizeof(int));
printf(" double value is %lf and size is %lu ytes.\n",c,sizeof(double));
return 0;
}
The header file limits.h defines limits of integer types and the user can use the constants defined in it.#include <limits.h>
#include <stdio.h>
int main()
{
printf("The max value of integer=%d",INT_MAX);
printf("The min value of integer=%d",INT_MIN);
return 0;
}
Macro |
Value |
Description |
CHAR_BIT |
8 |
Defines the number of bits in a byte. |
SCHAR_MIN |
-128 |
Defines the minimum value for a signed char. |
SCHAR_MAX |
+127 |
Defines the maximum value for a signed char. |
UCHAR_MAX |
255 |
Defines the maximum value for an unsigned char. |
CHAR_MIN |
-128 |
Defines the minimum value for type char and its value will be equal to SCHAR_MIN if char represents negative values, otherwise zero. |
CHAR_MAX |
+127 |
Defines the value for type char and its value will be equal to SCHAR_MAX if char represents negative values, otherwise UCHAR_MAX. |
MB_LEN_MAX |
16 |
Defines the maximum number of bytes in a multi-byte character. |
SHRT_MIN |
-32768 |
Defines the minimum value for a short int. |
SHRT_MAX |
+32767 |
Defines the maximum value for a short int. |
USHRT_MAX |
65535 |
Defines the maximum value for an unsigned short int. |
INT_MIN |
-2147483648 |
Defines the minimum value for an int. |
INT_MAX |
+2147483647 |
Defines the maximum value for an int. |
UINT_MAX |
4294967295 |
Defines the maximum value for an unsigned int. |
LONG_MIN |
-9223372036854775808 |
Defines the minimum value for a long int. |
LONG_MAX |
+9223372036854775807 |
Defines the maximum value for a long int. |
ULONG_MAX |
18446744073709551615 |
Defines the maximum value for an unsigned long int. |
LLONG_MIN |
-9223372036854775808 |
Minimumvalue for a variable of type long long |
LLONG_MAX |
9223372036854775807 |
Maximum value for a variable of type long long |
ULLONG_MAX |
18446744073709551615 (0xffffffffffffffff) |
Maximum value for a variable of type unsigned long long |
FLT_MAX |
3.402823466e+38F
1.7976931348623158e+308 |
Maximum representable floating point number |
FLT_MIN |
1.175494351e-38F
|
Minimum positive value |
The discussion can be found here https://cprogramktu.blogspot.com/2018/01/enumerated-data-type.html
arrays
The discussion can be found here https://cprogramktu.blogspot.com/2018/01/arrays.html
structure and unions
The discussions can be found here https://cprogramktu.blogspot.com/2018/01/structures-and-unions.html
pointers
The discussions can be found here https://cprogramktu.blogspot.com/2018/02/pointers.html
Comments
Post a Comment