0% found this document useful (0 votes)
16 views27 pages

I Unit DS

The document discusses self-referential structures in C, providing examples and types such as single and multiple links. It also covers enumerated data types, explaining how to define them and providing a sample code. Additionally, the document introduces the 'typedef' keyword in C, illustrating its use to create new names for existing data types.

Uploaded by

lavarajugadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views27 pages

I Unit DS

The document discusses self-referential structures in C, providing examples and types such as single and multiple links. It also covers enumerated data types, explaining how to define them and providing a sample code. Additionally, the document introduces the 'typedef' keyword in C, illustrating its use to create new names for existing data types.

Uploaded by

lavarajugadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Structures and Unions

UNIT I
G.LAVARAJU
Asst. Professor
Department of CSE
Aditya University
Self Referential Structures
Self Referential structures are those structures that
have one or more pointers which point to the same
type of structure, as their member.
Monday, February 17, G.LAVARAJU
2025
Program example:
struct node {
int data1;
char data2;
struct node* link;
};

int main()
{
struct node ob;
return 0;
}
Monday, February 17, G.LAVARAJU
2025
• Types of Self Referential Structures
Self Referential Structure with Single Link
Self Referential Structure with Multiple Links

Monday, February 17, G.LAVARAJU


2025
#include <stdio.h>
struct node {
int data1;
char data2;
struct node* link;
};
int main()
{
struct node ob1; // Node1
ob1.link = NULL;
ob1.data1 = 10;
ob1.data2 = 20;
Monday, February 17, G.LAVARAJU
2025
struct node ob2;
ob2.link = NULL;
ob2.data1 = 30;
ob2.data2 = 40;
ob1.link = &ob2;
printf("%d", ob1.link->data1);
printf("\n%d", ob1.link->data2);
return 0;
}
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025
ENUMERATED DATA
TYPES
Enumeration or Enum in C is a special kind of
data type defined by the user. It consists of
constant integrals or integers that are given
names by a user
Syntax to Define Enum in C
• An enum is defined by using the ‘enum’ keyword in C, and the use of a
comma separates the constants within.
The basic syntax of defining an enum is:
enum enum_name{int_const1, int_const2, int_const3, …. int_constN};

In the above syntax, the default value of int_const1 is 0, int_const2 is


1, int_const3 is 2, and so on. However, you can also change these
default values while declaring the enum.

Monday, February 17, G.LAVARAJU


2025
#include <stdio.h>
enum days{Sunday=1, Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday};
int main()
for(int i=Sunday;i<=Saturday;i++)
{ printf("%d, ",i);
}
return 0;
}
Output 1, 2, 3, 4, 5, 6, 7
Monday, February 17, G.LAVARAJU
2025
C 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.
When names of datatypes become difficult to use in
programs, typedef is used with user-defined datatypes,
which behave similarly to defining an alias for commands.
#include <stdio.h>
typedef int Integer;
int main() {
Integer n = 10;
printf("%d", n);
return 0;
}
Output:
10
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025
INTRADUCTION TO
DATASTRURURE AND
TYPES OF DATA
STRUTURE
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025
Monday, February 17, G.LAVARAJU
2025

You might also like