Professional Documents
Culture Documents
Structure Assignment
Structure Assignment
Assignment
GE2B
Subject :- Computer Science
Topic :-Structure in C
Department :-Physics
• Title
• Author
• Subject
• Book ID
Defining a Structure
To define a structure, we must use the struct
statement. The struct statement defines a new data
type, with more than one member. The format of the
struct statement is as follows −
struct struct_name
{
data type variable 1;
data type variable 2;
……………
}structure variable;
For example:
struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
} book;
#include <stdio.h>
#include <string.h>
struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
};
int main( )
/* book 1 specification */
return 0;
Pointers to Structures
struct_pointer->title;
For Example:
#include <stdio.h>
#include <string.h>
struct Books {
char title[50];
char author[50]
char subject[100];
int book_id;
};
/* function declaration */
int main( ) {
/* book 1 specification */
/* book 2 specification */
printBook( &Book1 );
printBook( &Book2 );
return 0;
struct student
int roll;
char name[20];
main()
int i;
for(i=0;i<5;i++)
scanf("%s",stu[i].name);
printf("details of students");
printf("%d",stu[i].roll);
printf("%s",stu.name);
getch();
#include<conio.h>
struct student
int roll;
char name[20];
main()
int i;
for(i=0;i<5;i++)
{
scanf("%d".&stu[i].roll);
scanf("%s",stu[i].name);
printf("details of students");
printf("%d",stu[i].roll);
printf("%s",stu.name);
getch();
#include <string.h>
struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
};
/* function declaration */
int main( ) {
struct Books Book1; /* Declare Book1 of type Book */
/* book 1 specification */
/* book 2 specification */
printBook( Book1 );
printBook( Book2 );
return 0;
}
void printBook( struct Books book ) {
----------------------0--------------------