C data types format specifiers is important topic. These data types in C is easy topic as well. You will use these in most programs. You will use data types in C to refer extensive system. This system will declare either functions or C variables. In addition, variables and functions can be of different types. You will learn more about data types in C with examples here.
You must remember that variable type determines space. This space is about storage. Moreover, it interprets bit pattern stored. However, these C data types have different classification. Keep reading to know more about them.
Name of data type | Description |
Basic Types | These are arithmetic types. Classification is as follows: integer types and the floating-point types |
Derived types | Pointer, Array, Structure, Function and Union types |
Enumerated types | These are also arithmetic types. They define variables. These can assign certain discrete integer values in program |
The type void | Type specifier void will state that there is no value |
Array and structure types together are aggregate types. You must remember that function type indicates return value of function.
List of standard integer types, storage sizes and value range
Type | Value range | Storage size |
unsigned char | 0 to 255 | 1 byte |
char | -128 to 127 or 0 to 255 | 1 byte |
signed char | -128 to 127 | 1 byte |
int | -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 | 2 or 4 bytes |
unsigned int | 0 to 65,535 or 0 to 4,294,967,295 | 2 or 4 bytes |
long | -2,147,483,648 to 2,147,483,647 | 4 bytes |
unsigned long | 0 to 4,294,967,295 | 4 bytes |
short | -32,768 to 32,767 | 2 bytes |
unsigned short | 0 to 65,535 | 2 bytes |
sizeof operator in C
You may use sizeof operator in C. This will get exact size of variable or type. In addition, sizeof(type) will yield storage size of object. Or even the type in bytes.
Example program
Void type in C programming language
Name of the type | Description |
Function returns as void | You must remember that many functions in C do not return any value or return void. Additionally, function with no return value has void as return type. Example void exit (int status); |
Pointers to void | A pointer of type void * will represent address of object. However, it will not be type. Example is memory allocation function void *malloc( size_t size );
Because here, it will return pointer to void. Moreover, you can cast it to other data type
|
Function arguments as void | Apart from above two, there are other functions in C. These functions do not accept parameters. So, remember that a function with no parameter can never accept void. Example is int rand(void); |
Floating-point type in C programming language
Name of the Type | Value range | Storage size | Precision |
float | 1.2E-38 to 3.4E+38 | 4 byte | It is 6 decimal places |
long double | 3.4E-4932 to 1.1E+4932 | 10 byte | Here, there are 19 decimal places |
double | 2.3E-308 to 1.7E+308 | 8 byte | It is 15 decimal places |
Header file float.h will define macros. Macros in C language allow you to use values and real numbers in programs. Also know about Operators in C.
Example program
No comments:
Post a Comment