In C programming language, data types are used for declaring variables and functions.The type of a variable determines how much space it takes in storage and how the bit pattern stored is interpreted.
The data types in C can be classified as follows: 1. Basic Types: They are arithmetic types and are of the two types: (a) integer types and (b) floating-point types. 2.Enumerated types: They are also arithmetic types and they are used to define variables that can only be assigned certain discrete integer values throughout the program. 3.The type void: The type specifier void indicates the no value . 4.Derived types: They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types. The array types and structure types are the aggregate data types. The data type of a function specifies the type of function's return value.The basic data types are in the following section Integer Types:Following table shows you details about standard integer types with its storage sizes and value ranges: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 byte -32,768 to 32,767 or -2,147,483,648 to 2,147,483,648 unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,296 short 2 bytes 32,768 to 32,765 unsigned short 2 bytes 0 to 65,536 long 4 bytes -2,147,483,648 to 2,147,483,646 unsigned long 4 bytes 0 to 4,294,967,294 To get the size of the a variable on a particular platform, we can use the sizeof function. The sizeof(type) yields the storage size of the object or type in bytes.Example #include <stdio.h> #include <limits.h> int main() { printf("Storage size for int : %d \n", sizeof(int)); return 0; } result on Linux: Storage size for int : 4 Floating-Point Types:Following table shoes you details about standard floating-point types with sizes , ranges and their precision:Type Storagesize 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 The header file float.h defines macros that allow you to use these values and other details about the binary representation of real numbers in your programs. #include <stdio.h> #include <float.h> int main() { printf("Storage size for 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 compilation , it produces the following result on Linux: Storage size for float : 4 Minimum float positive value: 1.175493E-38 Maximum float positive value: 3.402823E+38 Precision value: 6 The void Type:Following table shoes you details about the void type.1.Function returns as void: A function with no return value has the return type as void. For example void exit (int status); 2.Function arguments as void: A function with no parameter . For example, int example(void); 3.Pointers to void: A pointer of type void represents the address , but not its type. |
|||
C - Overview | |||
C - Basic Syntax | |||
C - Data Types | |||
C - Variables | |||
C - Constants | |||
C - Storage Classes | |||
C - Operators | |||
C - Decision Making | |||
C - Loops | |||
C - Functions | |||
C - Scope Rules | |||
C - Arrays | |||
C - Pointers | |||
C - Strings | |||
C - Structures | |||
C - Unions | |||
C - Bit Fields | |||
C - Typedef | |||
C - Input & Output | |||
C - File I/O | |||
C - Preprocessors | |||
C - Header Files | |||
C - Type Casting | |||
C - Error Handling | |||
C - Recursion | |||
C - Variable Arguments | |||
C - Memory Management | |||
C - Command Line Arguments |
Saturday, 23 November 2013
Home »
C language
» Data Types in C
0 comments:
Post a Comment