0% found this document useful (0 votes)
3 views11 pages

Structure

The document explains the concept of structures in C programming, describing them as heterogeneous user-defined data types that can contain different data types. It outlines the syntax for defining structures, declaring structure variables, and initializing them, as well as accessing their elements. Additionally, it covers advanced topics such as structures within structures and arrays of structures.

Uploaded by

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

Structure

The document explains the concept of structures in C programming, describing them as heterogeneous user-defined data types that can contain different data types. It outlines the syntax for defining structures, declaring structure variables, and initializing them, as well as accessing their elements. Additionally, it covers advanced topics such as structures within structures and arrays of structures.

Uploaded by

B SD
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Structure

• Structure :-
• A structure in C is heterogeneous user defined data type or A structure
is a collection of different data type.
• Syntax :-
struct [<struture_type_name>]
{
[<type> <variable_name> [,<variable_name>,…]];
[<type> <variable_name> [,<variable_name>,…]];

}[<structure_variable>];
Structure
• Structure :-
• Tags serves as a name that can be used for a particular template of the
structure.
• <structure_type_name>
• is optional tag name that refers to the structure type.

• <structure_variables>
• refer to the data definition, also optional.
Structure
• Structure :-
• struct student
{ int rollno;
int subject;
float marks;
};

• Members of a structure may be of any common data type.


• All members name within a particular structure must be different.
• Individual members can not be initialized inside structure declaration.
Declaration of structure variable
• Structure :-
• Structure variables can be declared in two different ways.
• (1)In the structure declaration
• struct student
{ int rollno;
int subject;
float marks;
} student1, student2,student3;
Declaration of structure variable
• Structure :-
• If the variables of the structure are not required, the tag name student
can be omitted.
• struct { int rollno;
int subject;
float marks;
};
Declaration of structure variable
• Structure :-
• 2. Using the structure tag name
The variables of a structure may also declared separately by
using the structure tag .
struct student student1,student2,student3;
Declaration of structure variable
• Structure Initialization
A variable of structure can be initialized during declaration :-

struct student1 = {“Rashmi”,1011,98};

Accessing Elements :- [Link]= 80;


Structure within Structure
• The individual members of a structure can be other structure as well.
There are two types of declaring such a structure.

struct date struct person


{ int day; {char name[25];
int month; struct date
int year; { int day;
}; int month;
struct person int year;
{char name[25]; }birthday;
struct date birthday; float salary;
float salary;}; };
Array of Structure
• We can create array of structure similar to any other datatype. Here are
the two different ways of creation of array of structure.

struct person struct person


{char name[25]; {char name[25];
struct date birthday; struct date birthday;
float salary; float salary;
}emprec[10]; };
Struct person emprec[10];
Emprec[1].[Link] =24;
Precedence of DOT operator
• The dot operator is a member of the highest precednece group and
associates from left to right.
• Dot Operator have precedence over various arithmetic, relational,
logical, assignment and unary operator.

• So, ++[Link] = ++([Link])

You might also like