0% found this document useful (0 votes)
5 views

Singly Linked List

Uploaded by

danieldivya871
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Singly Linked List

Uploaded by

danieldivya871
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Singly Linked List

o Linked List can be defined as collection of objects called nodes that are randomly
stored in the memory.
o A node contains two fields i.e. data stored at that particular address and the pointer
which contains the address of the next node in the memory.
o The last node of the list contains pointer to the null.

Operations on Singly Linked List


 Traversal
 Searching
 Insertion:
o Insert at the beginning
o Insert at the end
o Insert at a specific position
 Deletion:
o Delete from the beginning
o Delete from the end
o Delete a specific node

typedef
The typedef is a keyword that is used to provide existing data types with a new name. The
C typedef keyword is used to redefine the name of already existing data types.
C typedef Syntax
typedef existing_name alias_name;
Program
#include <stdio.h>
int main()
{
typedef int unit;
unit i;
i=10;
printf("Value of i is :%d",i);
return 0;
}
Output:
Value of i is :10

C Unions
A union is a special data type available in C that allows to store different data types in the
same memory location.
All the members of a union share the same memory location. Therefore, if we need to use the
same memory location for two or more members, then union is the best data type for that.
The largest union member defines the size of the union.
Defining a Union
Union variables are created in same manner as structure variables. The keyword union is
used to define unions in C language.
Syntax
Here is the syntax to define a union in C language −
union union_name {
datatype member1;
datatype member2;
...
};
Accessing the Union Members
To access any member of a union, we use the member access operator (.). The member
access operator is coded as a period between the union variable name and the union member
that we wish to access.

Syntax
union_name.member_name;

Example:

#include <stdio.h>
#include <string.h>
union student
{
char name[20];
char subject[20];
float percentage;
};

int main()
{
union student record;
strcpy(record.name, "Raju");
strcpy(record.subject, "Maths");
record.percentage = 86.50;
printf(" Name : %s \n", record.name);
printf(" Subject : %s \n", record.subject);
printf(" Percentage : %f \n", record.percentage);
return 0;
}
Output:
Name :
Subject :
Percentage: 86.500000

Union Structure

Each member has its own separate memory All members share the same memory
space. space.

The size of the union is determined by the The size of the structure is determined by
size of its largest member. the sum of the sizes of its members.

Only one member can be accessed at a Individual members can be accessed at a


time. time using the dot operator.

Only the first member can be initialized All members can be initialized individually
explicitly. or collectively.

Example: Example:
union student struct student
{ {
int id; int id;
char name[12]; char name[12];
}; };

Storage Classes

C storage classes define the scope (visibility) and lifetime


of variables and/or functions within a C Program. They precede the type that they modify.
We have four different storage classes in a C program −
 Automatic/auto
 register
 static
 extern
Automatic/auto/local
The auto is a default storage class for all variables that are declared inside a function or a
block. The keyword "auto", which is optional, can be used to define local variables.
The scope and lifetime of auto variables are within the same block in which they are
declared.

Example:

Output:

Extern/ Global:
The extern variables that are declared outside a function or a block. The keyword "extern",
Static:
Register

You might also like