Articles added in Mathematics Lab | Cyber Lab is now open | Astronomy Lab is now open | VLSI Lab is now open | 120 SEO Tips article published | More exciting articles coming soon!




6.1 Introduction to Structures

Structure:
A structure is a collection of items of same or different types, which are collectively representing an entity like student, employee, complex number, rectangle ,etc.

Declaration:
Struct tag(name of the structure)
{
type1 member1;
type2 member2;
.
.
.
typen member n;
};

Note:struct is a keyword.

e.g.
struct student
{
char name[30];
int roll;
int total;
};
Now student is a datatype. A variable of this type can be declared as:
student s1;

Members of s1 can be accessed as:
S1.name ---> string variable
S1.roll --->int variable
S1.total --->int variable

Note:
1) Structure can be declared inside or outside of functions. But normally structure will be declared before main() function.
2) Structure variables can be declared together with structure declaration.

e.g. struct student
{
----
----
----
}s1, s2;
Now s1 and s2 are variables of type student.
3) If structure variables are declared together with structure declaration then tag name can be omitted.
e.g.
struct
{
char name[30];
int roll;
int total;
}s1,s2;
Now s1 and s2 are two structure variables with 3 members each.







CACKLE comment system





Programming Resources
Computer Networking Fundamentals Android Application