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
Data Types in C
Related Posts:
Decision Making Structure In C Decision making structures allows the programmer to specify one or more conditions to be evaluated or tested by the compiler or , along with a statement or set of statements to be executed if the condition is … Read More
Constant and Literals in c The constants refer to fixed values that the program may not change during its execution. These values are also called literals. C Programming Constants can be of any of the data types like an integer … Read More
Operators in C An operator is a symbol that instruct the compiler to perform specific mathematical or logical operation. C language has following type of operators: C Programming • Arithmetic Operators • … Read More
C language 'C' is a well known programming language which was developed by Dennis Ritchie in 1972 in AT&T Bell Labs. This programming language was influenced by B , BCPL , ALGOL, and some other programming… Read More
Storage Classes in c A storage class in C defines the scope (visibility) and life-time of a variables and/or a functions .These specifiers precede the type that they modify. There are some storage classes, which are used in a C Pr… Read More
0 comments:
Post a Comment