Академический Документы
Профессиональный Документы
Культура Документы
07/08/16
AMIT SHARMA
Declaring a Structure
struct
{
type
type
type
.
.
type
};
07/08/16
sname
var1;
var2;
var3;
varN;
Structure
template
sname is called tag makes it possible to
declare other variable of the same structure
type without having to rewrite the template
itself. Its a type name.tag is optional.
Array of Structures
07/08/16
Arrays in structures
struct student_type
{
char name[25];
int roll;
int marks;
char grade;
};
struct student stud_list[50];
07/08/16
07/08/16
stud[6].marks
Rajni Bhalla
CSE/IT
name
07/08/16
roll
marks
main()
{
Struct student
{
Char name[30];
int roll;
Float marks;
};
Struct student stud[30];
Int n,I;
Printf(\n enter the number of students in the class);
Scanf(%d,&n);
Printf(\nenter the records of the student);
For(i=0;i<n;i++)
{
Printf(\n name :); gets(stud[i].name);
Printf(\n roll :); scanf(%d,& stud[i].roll);
Printf(\n age :); scanf(%d,& stud[i].marks);
}
getch();
}
07/08/16
07/08/16
Union
Union:
Union is similar as structure. The major distinction between them in
terms of storage.
In structure each member has its own storage location whereas all
the members of union uses the same location.
The union may contain many members of different data type it can
handle only one member at a time union can be declared using the
keyword union.
Hold only one object at a time
Union requires bytes that are equal to the number of bytes required
for the largest members.
Eg: union contains char,int &long then the number of bytes reserved
in the member for the union is 4 bytes.
07/08/16
Structure
Union
Union item
{
int m;
float x;
char c;
} code;
This declare a variable code of type union item.
07/08/16
THANKYOU
YOU
THANK
AMIT SHARMA
11ECU023
07/08/16