This document discusses data types in C programming. It describes primitive data types like integers, floats, characters and their syntax. It also covers non-primitive data types like arrays, structures, unions, and linked lists. Arrays store a collection of similar data types, structures group different data types, and unions store different types in the same memory location. Linked lists are dynamic data structures using pointers. The document also provides overviews of stacks and queues, describing their LIFO and FIFO properties respectively.
2. Data type specifies the type of data stored in a variable.
Data types in C programming language enables the
programmers to appropriately select the data as per
requirements of the program and the associated
operations of handling it.
The data type can be classified into two types Primitive
data type and Non-Primitive data type
3. The primitive data types are the basic data types that are
available in most of the programming languages.
The primitive data types are used to represent single values.
Primitive data are only single values, they have not special
capabilities.
Data structure that normally are directly operated upon by
machine level instructions are known as primitive structure
and data type.
4. Integer(int): This is used to represent a number
without decimal point.
Eg: 12, 90
Float and Double: This is used to represent a number
with decimal point.
Eg: 45.1, 67.3
Character : This is used to represent single character
Eg: ‘C’, ‘a’
5. Syntax for integer:
int variable_name;
Syntax for float:
float variable_name;
Syntax for double:
double variable_name;
Syntax for chracter:
char variable_name;
6. Datatype Size(in bytes) Range
Integer
int
signed int
unsigned int
short int
signed short int
unsigned short int
long int
signed long int
unsigned long int
2
2
2
1
1
1
4
4
4
-32,768 to 32,767
-32,768 to 32,767
0 to 65535
-128 to 127
-128 to 127
0 to 255
-2,147,483,648 to
2,147,483,647
Same as Above
0 to 4,294,967,295
Float &
Double
float
double
long double
4
8
10
3.4E-38 to 3.4E+38
1.7E-308 to 1.7E+308
3.4E-4932 to
1.1E+4932
Character
char
signed char
unsigned char
1
1
1
-128 to 127
-128 to 127
0 to 255
7. The data types that are derived from primary data types are
known as non-Primitive data types.
These data types are used to store group of values.
The non-primitive data types are,
Arrays
Structure
Union
linked list
Stacks
Queue
8. An array is used to store a collection of variables of the same
data type.
A specific element in an array is accessed by an index.
All arrays consist of contiguous memory locations.
Syntax for declaring array is,
data type arrayName [ arraySize ];
Initializing Arrays,
double balance[5] = {1000.0, 2.0, 3.4, 7.0, 50.0};
The lowest address corresponds to the first element and the
highest address to the last element.
9. Structure is another user defined data type available in C
that allows to combine data items of different kinds.
Structures are used to represent a record.
To define a structure, we must use the struct statement.
The struct statement defines a new data type, with more
than one member. The format of the struct statement is as
follows −
struct [structure tag] { member definition; member
definition; ... member definition; } [one or more structure
variables];
struct Books { char title[50]; char author[50]; char
subject[100]; int book_id; } book;
10. A union is a special data type available in C that allows
to store different data types in the same memory
location. We can define a union with many members,
but only one member can contain a value at any given
time. Unions provide an efficient way of using the
same memory location for multiple-purpose.
To define a union, we must use the union statement
union [union tag] { member definition; member
definition; ... member definition; } [one or more union
variables];
11. Here is the way that we could define a union type
named Data having three members i, f, and str −
union Data { int i; float f; char str[20]; } data;
The memory occupied by a union will be large enough
to hold the largest member of the union. For example,
in the above example, Data type will occupy 20 bytes of
memory space because this is the maximum space
which can be occupied by a character string.
12. The linked list consists of series of structures. They are
not required to be stored in adjacent memory location.
Each structure consists of a data field and address
field. Address field contains the address of its
successors.
The actual representation of the structure is as follow:
A variable of the above structure type is conventionally
known as node.
Here the representation of a linked list of three nodes:
Node A Node B Node C
Data Address
X1 X2 X3
13. Node A stored data X1 and the address of the successor node B.
Node B stores the data X2 and the address of its successor node
C. node C contains the data X3 and its address field is grounded,
indicating it does not have successor.
There are three types of Linked List:
Singly Linked List
Doubly Linked List
Circular Linked List
Linked lists are the best and simplest example of a dynamic data
structure that uses pointers for its implementation.
Items can be added or removed from the middle of the list.
There is no need to define an initial size.
14. Stack can be implemented
using the Linked List or
Array.
Stack is LIFO Structure [ Last
in First Out ]
Stack is Ordered List
of Elements of Same Type.
Stack is Linear List
In Stack all Operations such
as Insertion and
Deletion are permitted at
only one end called Top
Position of Top Status of Stack
-1 Stack is Empty
0
First Element is
Just Added into
Stack
N-1
Stack is said to
Full
N
Stack is said to
be Overflow
15. Queue is a specialized data storage structure (Abstract data
type).
Arrays access of elements in a Queue is restricted.
It has two main operations enqueue and dequeue.
Insertion in a queue is done using enqueue function and
removal from a queue is done using dequeue function.
An item can be inserted at the end of the queue and
removed from the front of the queue.
It is therefore, also called First-In-First-Out (FIFO) list.
16. Queue has important properties,
capacity stands for the maximum number of elements Queue
can hold,
size stands for the current size of the Queue,
elements is the array of elements,
It has two basic implementations,
Array-based implementation – It’s simple and efficient but
the maximum size of the queue is fixed.
Singly Linked List-based implementation – It’s complicated
but there is no limit
on the queue size, it is subjected to the available memory.