Data Types
The
nature of variable is referred as data type.The data type determines
the kind of data which is going to be stored in the variable declared of
that type. It plays important role to declare variables. It prevents
invalid data entry in the program. The biggest advantage of data type is
efficient use of memory space.
1.Basic data types :
Data type can be classified into following sub-heads.
1.Basic Data Types
2.User Defined Data Types
3.Derived Data Types
1.Basic data types :
Data Type
|
Descriptions
|
Keyword
|
Memory
|
Conversion
String
|
Range
(on 16 bit machine)
|
Integer
|
Whole number
|
int
|
2 bytes
|
%d
|
-32768 to +32767
|
Character
|
Single characte
|
char
|
1 bytes
|
%c
|
-128 to +127
|
Floating
Point |
Real number
(precision:- 06 places) |
float
|
4 bytes
|
%f
|
3.4e-38 to + 3.4e+38
|
Double-Precision
floating point |
Real number
(precision:- 12 places) |
double
|
8 bytes
|
%lf
|
1.7e-308 to 1.7e+308
|
2.User defined Data Types:
User defined data types are those data types that define by the users.
User defined data types are those data types that define by the users.
a.Type Defination:-
Type definition is used to provide an alternate name to existing data type.
Type definition does not create a new data type; it just assign a new name.
The keyword “typedef” is used to fulfil the purpose means using keyword “typedef” user can change name of data type.
Ex- if user want change name of data type ‘int’ to ‘number’ than use the “typedef” keyword.
The Syntax is:
typedef ‘data type’ ‘new name’ ;
ex-
#include<stdio.h>
typedef int number
void main()
{
number x=1;
printf(“X=%d”,x);
}
output:- 1
b.Enumerator:
Enumerator data type is defined to store specific set of constant.
Enumerator data type essentially defines a set of constants of the type int.
The variables of enumerated data type can store only one value from
Specific set only. The Keyword “enum” is used to create enumerated data type
The syntax is
enum “enum_tag” {enumeration constants};
enum enum_tag variables;
Enumerated data type makes programs more readable(advantage).
The enumerated values cannot be used directly in I/O functions(Disadvantages)
# include<stdio.h>
enum division {Fail,First,Second,Third} ; /* 'enum division' is a user defined data type */
void main()
{
enum division status; /*'status' is a variable of data type 'enum division' */
status=First; /* value of 'status' is first*/
if(status==First)
printf("Congratulation");
else
printf("Put Efforts");
}
3. Derived Data Type:
Derived
data types are devised from existing data types. “C” language supports
various derived data type like array, structure, union, pointer etc.
Array
is the collection of homogeneous data while structure and union are the
collection of heterogeneous data .pointer stores the address of some
other variables.
Click to edit your
Website Header.
Website Header.
Drag to Move
good
ReplyDelete