Singly Linked List
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.
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 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
Example:
Output:
Extern/ Global:
The extern variables that are declared outside a function or a block. The keyword "extern",
Static:
Register