(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
Structure for cpu
1. STRUCTURE
Prepared By: Jay R. Patel
Enrollment no.:160410119071
Id. No.:16bemev137
Mechanical-2
Batch: C
Guided By: Uma Dave
2. Basic Of Structure
Structure is a collection of different types of
variables under a single name.
Structure is used to represent logically related
data.
It is same as records used in “PASCAL”.
The structure is a very powerful and important
tool which fulfills requirements of complex
problems.
3. A simple example of a structure is information
about students,
** students can be represented by roll-no,
name, branch, joining date etc.
** It may be possible that a variable in the
structure is also can be structure.
i.e. A variables in structure can be also
devided into components.
For example, one variable ‘joining date’ of
student which consist the date, month and
year which are also variables.
4. The general format to define a structure is given
as:
struct_tag {
data_type member_variabe1;
data_type member_variabe2;
.
.
.
} s1,s2,s3;
Defining Of Structure & Members
5. *** In previous slide ,
struct is a reserve word and used to define a
structure.
struct_tag is an optional tag which provides type
name to the structure.
The members of structures are enclosed in pair of
{}.
Each member consist of a datatype and variable
name followed by semicolon(;).
After making declaration variables of student type
are created as follows:
struct student s1,s2,s3;
The defination(declaration) is ended with
semicolon(;).
6. Then cosider following example of a
structure, defining a student record,
struct student {
int roll_no;
char name[20];
int age;
} s1,s2,s3;
7. Members of a structure can be accessed and used
individually in a problem.
Following syntax is used to access the members of a
structure.
structure_name is the name of a structure variable &
member_name is the name of the member of structure. &
structure member operator “.” (dot) connects member
name to structure name.
for example,
s1.age
Here, s1 is structure variable and age is member name
which is type of student.
And following statement assigns value 20 to s1.age
s1.age = 20;
Accessing Structure Members
Structure_name.member_name
8. The Age of student s1 can be read from
keyboard as
scanf(“%d”,&s1.age);
Following examples shows the use of structure
members in various statements:
1. s2.roll_no = 10;
2. (s2.roll_no)++;
3. printf(“%d”,s1.roll_no);
4. strcpy(s1.name,”akshat”);
5. printf(“%s”,s1.name);
9. A structure can be member of another structure. This is
known as nesteding of structure or structure within
structure.
Consider the student record includes birth date. It is define as
follows:
struct date {
int d;
int m;
int y;
};
struct student {
int roll_no;
char name[20];
struct date birth_date;
};
student is a variable, then day of birth define as:
s1.birth_date.d
which represents one integer.
Nested Structures
10. •In previous slide the structure is also be written as :
struct student {
int roll_no;
char name[20];
struct date {
int d;
int m;
int y;
} birth_date;
};
In this defination, date is part of student and its variables can not be
created independently.
However, it looks like natural nesting.
The tag name date can be define in this case without any loss.