[C] Data Type
Data type in C
integer types
Type | Storage size | Value 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 or 4 bytes | -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 |
unsigned int | 2 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 | 8 bytes | -9223372036854775808 to 9223372036854775807 |
unsigned long | 8 bytes | 0 to 18446744073709551615 |
'limits.h' have data of limit numbers of inter types.
INT_MAX, INT_MIN
USHRT_MAX, USHRT_MIN ect.
float types
Type | Storage size | Value range | Precision |
float | 4 byte | 1.2E-38 to 3.4E+38 | 6 decimal places |
double | 8 byte | 2.3E-308 to 1.7E+308 | 15 decimal places |
long double | 10 byte | 3.4E-4932 to 1.1E+4932 | 19 decimal places |
void types
Types and Description |
Function returns as void There are various functions in C which do not return any value or you can say they return void. A function with no return value has the return type as void. For example, void exit (int status); |
Function arguments as void There are various functions in C which do not accept any parameter. A function with no parameter can accept a void. For example, int rand(void); |
Pointers to void A pointer of type void * represents the address of an object, but not its type. For example, a memory allocation function void *malloc( size_t size ); returns a pointer to void which can be casted to any data type. |
typedef
'typedef' is a reserved keyword in the C and C++ programming languages. It is used to create an alias name for another data type.
1
2
|
typedef unsigned int ui;
ui a; // same as 'unsigned int a;'
|
type casting
· (type) variable
· (type) value
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include <stdio.h>
int main()
{
int num1 = 32;
int num2 = 6;
float num3;
num3 = num1 / num2; // Compile error occurs
printf("%f\n", num3); // 5.000000
num3 = (float)num1 / num2; // cast 'num1' to float type
printf("%f\n", num3); // 5.333333
return 0;
}
|
s |