Header Ads

Breaking News

C tutorials Data types in C

Data Types:
Data types are used for maintaining variables or functions of different types. Data types are referred to as extensive system C. The types of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.
Description of types:

            Basic Types:

Arithmetic and are further classified into a) integer types, b)Floating Types.

Enumerated Types:
Also arithmetic types and these are used for define variables that can be certain discrete-integer data throughout the program.

The void types:
The types specifier void indicates that no data is available.

Derived Types:
Consists of a)Pointer types, b)Array types, c)Structure types, d) Union types. And e)Function types.

Array types and structure types are referred to as the aggregate types. The kind of function specifies the types of the function’s return value. You shall see the basic types of data types in the following section.


Types
Size of storage
Value range
Char
1 byte
-128 to 127 or 0 to 255
Unsigned
1 byte
0 to 255
Signed char
1 byte
-128 to 127
Int
2 or 4 bytes
-32768 to +32767 or  -2147483648 to + 2147483647
Unsigned int
2 o 4 bytes
0 to 65535 or 0 to 4292967295
Short
2 bytes
-32768 to +32767
Unsigned short
2 bytes
0 to 65535
Long
4 bytes
-2147483648 to + 2147483647
Unsigned long
4 bytes
0 to 4292967295













Integer types:

The following tables provide the details of standard integer types with their value ranges and data size.
The get the exact size of a type or a variable an expression sizeof(type) yields the storage size of the subject or type in bytes.
Example:
#include<stdio.h>
#include<limit.h>
int main()
{
printf(“Storage size for int :%d\n”,sizeof(int));
return 0;
}


Output on LINUX:
Storage size for int:4
Floating-point types:
The below tables provide details about syntax of floating-point types with their sizes and value ranges and precision.
Types
Storage sizes
Value range
Precision
Float
4 bytes
1.2E-38 to 3.4E +38
6 decimal places
Double
8 bytes
2.3E-308 to 1.7E+308
15 decimal places
Long double
10 bytes
3.4E-4932 to 1.1e+4932
19 decimal places
Float.h is a header file which defines macros that allow you to these values and other details about the binary representation of real numbers in programs.
Examples:
#include<stdio.h>
#include<float.h>
Int main()
{
printf(“Storage size of float:%d/n”,sizeof(float));
printf(“Minimum float positive value:%E\n”,FLT_MIN);
printf(“Maximum float positive value:%E\n”,FLT_MAX);
printf(“Precision value:%d\n”,FLT_DIG);
return 0;
}

After executing the above program, the output is:
Storage size of float:4
Minimum float positive value:1.175494E-38
Maximum float positive value:3.402823E+38
Precision values:6

The void types:

The void type have no specifies value, it is used three kinds of situations.
Types and description:

Function returns as void:

There are various functions in C which do not return with any value or you can tell they return void. A function with no value has return type as void. For example void exit(int status).
Function arguments as void:
There are various function in C which do not accept any parameter. For example int rand(void);

Pointer 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_tsize); returns a pointer to void which can be cast to any data types.

No comments