INTRODUCTION OF STRUCTURE
Structure is a method of packing data of different
types. A structure is a convenient method of handling
a group of related data items of different data types.
If we need to use a collection of different data type
items it is not possible using an array, so we can
use a structure.
To declare a structure, we use the keyword struct. The collection of
data items that need to be a part of the structure are then declared
within the braces.
Struct structure_name
{
data type member1;
data type member2;
……;
……;
};
r example:
Struct lib_books
{
char title[20];
char author[15];
int pages;
float price;
};
Struct lib_books
{
char title[20];
char author[15];
int pages;
float price;
};
struct lib_books book1,book2,book3;
2:
Struct lib_books
{
char title[20];
char author[15];
int pages;
float price;
}book1,book2,book3;
1. struct lib_books book1={“ C++ ”,400,250.00};
2. book1.pages=400;
3. book1.price=250.00;
4. scanf(“%s”,book1.name);
5. scanf(“%d”,&book1.pages);
1:
#include<stdio.h>
#include<conio.h>
struct student
{
char name[20];
int roll;
char branch[10];
}s;
printf(“n enter name”);
scanf(“%s”,s.name);
s.roll=16;
s.branch=“cs”;
printf(“name=%s roll no.=%d
branch=%s”,s.name,s.roll,s.branch);
getch();
}
struct student
{
char name[20];
float marks;
};
void main()
{
struct student s1={“juhi”,90};
struct student s2;
s2=s1;
printf(“n name= %s n marks=%f”,s1.name,s1.marks);
printf(“n name= %s n marks=%f”,s2.name,s2.marks);
getch();
}
 Structures hold data that belong together.
 Examples:
 Student record: student id, name, major,
gender, start year, …
 Bank account: account number, name,
currency, balance, …
 Address book: name, address, telephone
number, …
 In database applications, structures are called
records.
~THANK YOU~
RISE FOR QUESTIONS PLEASE!!

Introduction of structure

  • 1.
  • 2.
    Structure is amethod of packing data of different types. A structure is a convenient method of handling a group of related data items of different data types. If we need to use a collection of different data type items it is not possible using an array, so we can use a structure.
  • 3.
    To declare astructure, we use the keyword struct. The collection of data items that need to be a part of the structure are then declared within the braces. Struct structure_name { data type member1; data type member2; ……; ……; }; r example: Struct lib_books { char title[20]; char author[15]; int pages; float price; };
  • 4.
    Struct lib_books { char title[20]; charauthor[15]; int pages; float price; }; struct lib_books book1,book2,book3; 2: Struct lib_books { char title[20]; char author[15]; int pages; float price; }book1,book2,book3;
  • 5.
    1. struct lib_booksbook1={“ C++ ”,400,250.00}; 2. book1.pages=400; 3. book1.price=250.00; 4. scanf(“%s”,book1.name); 5. scanf(“%d”,&book1.pages);
  • 6.
    1: #include<stdio.h> #include<conio.h> struct student { char name[20]; introll; char branch[10]; }s; printf(“n enter name”); scanf(“%s”,s.name); s.roll=16; s.branch=“cs”; printf(“name=%s roll no.=%d branch=%s”,s.name,s.roll,s.branch); getch(); }
  • 7.
    struct student { char name[20]; floatmarks; }; void main() { struct student s1={“juhi”,90}; struct student s2; s2=s1; printf(“n name= %s n marks=%f”,s1.name,s1.marks); printf(“n name= %s n marks=%f”,s2.name,s2.marks); getch(); }
  • 8.
     Structures holddata that belong together.  Examples:  Student record: student id, name, major, gender, start year, …  Bank account: account number, name, currency, balance, …  Address book: name, address, telephone number, …  In database applications, structures are called records.
  • 9.
    ~THANK YOU~ RISE FORQUESTIONS PLEASE!!