Different Data Types in C'
Different Data Types in C'
Different Data Types in C'
‘C’
Submitted by :
Manish Mann
ECE/09/128
Introduction
Data Type: set of values together with a set of
operations is called a data type
Data types are used to store various types of
data that is processed by program.
Data type attaches with variable to determine
the number of bytes to be allocate to variable
and valid operations which can be performed
on that variable.
Data Types
are :
1. structure
2. union
3. enumeration
User Defined Data Types : Structure
A structure is a variables referenced under one name,
providing a convinient means of keeping related
informantion together.
The variables that make up structure are called structure
elements.
Keyword struct is used to construct a structure.
Syntax :
struct name{
structure elements;
};
A structure is diff. from an array as, array is the collection of
similar data types where as structure is collection of diff.
data types.
User Defined Data Types : Union
Unions in C are related to structures and are
defined as objects that may hold (at different
times) objects of different types and sizes.
They are analogous to variant records in other.
Unlike structures, the components of a union all
refer to the same location in memory
programming languages.
The size of a union is equal to the size of its
largest component type.
Keyword union is used to declare and create a
union.
User Defined Data Types :
Enumeration
Used to create a group of values which are named constants
in C, C++, C#, Java, etc.
Examples in C/C++/C#:
enum days {Mon, Tue, Wed, Thu, Fri, Sat, Sun}; // Mon = 0, Tues =
1, . . ., etc.
days today, yesterday = Wed;
today = yesterday + 1;
The first constant in an enumeration is assigned the value
zero, and each subsequent value is incremented by one over
the previous constant.
Specific values may also be assigned to constants in the
declaration, and any subsequent constants without specific
values will be given incremented values from that point
onward.
Why so many data types?????
The reason for providing so many data types
is to allow programmer to take advantage of
hardware characteristics.