SlideShare ist ein Scribd-Unternehmen logo
1 von 12
and STRUCTURE
1
Contents:
 Introduction
 Syntax and formation
 Variables and member accessing
 Nesting of structures
 Use of function and pointer in structure
2
Intro:
 Structure is another user defined data type like array
available in C , that allows to combine data items of
different kinds of data types, whereas arrays allow
only of same data type .
 Structures are used to represent a record. Suppose you
want to keep track of your books in a library. You might
want to track the following attributes about each book
− Title
− Author
− Subject
− Book ID
3
All these data can be saved under a
single name in STRUCTURE
Structure declarations
4
To define a structure, you 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 [structure tag] {
member definition;
member definition;
...
member definition;
} [one or more structure variables];
struct person
{
char name[50];
int cit_no;
float salary;
};
We can create the structure for a
person as mentioned above as:
Structure variable declaration
5
When a structure is defined, it creates a user-defined type
but, no storage is allocated. For the above structure of person,
variable can be declared as:
struct person
{
char name[50];
int cit_no;
float salary;
};
Inside main function:
struct person p1, p2, p[20];
Another way of creating sturcture variable
is: struct person
{
char name[50];
int cit_no;
float salary;
}p1 ,p2 ,p[20];
Member access
6
Accessing members of a structure
There are two types of operators used for accessing members
of a structure.
1. Member operator(.)
2. Structure pointer operator(->)
Any member of a structure can be accessed as:
structure_variable_name.member_name
Suppose, we want to access salary for variable p2. Then, it can
be accessed as:
p2.salary
Nested Structures
7
Structures can be nested within other structures in C
programming.
struct complex
{
int imag_value;
float real_value;
};
struct number{
struct complex c1;
int real;
}n1,n2;
Suppose you want to access imag_value for n2 structure
variable then,
structure member n1.c1.imag_value is used.
Sample program
CS 3090: Safety Critical Programming in C 8
Pointers to Structure :
9
We can define pointers to structures in the same way as we
define pointer to any other variable −
struct Books *struct_pointer;
Now, we can store the address of a structure variable in the
above defined pointer variable. To find the address of a
structure variable, place the '&'; operator before the
structure's name as follows −
struct_pointer = &Book1;
To access the members of a structure using a pointer to
that structure, you must use the -> operator as follows −
struct_pointer->title;
Example using function and pointer:
10
#include <stdio.h>
#include <string.h>
struct Books {
char title[50];
char author[50];
char subject[100];
int book_id;
};
/* function declaration */
void printBook( struct Books *book );
int main( ) {
struct Books Book1; /* Declare Book1 of type Book */
struct Books Book2; /* Declare Book2 of type Book */
/* book 1 specification */
strcpy( Book1.title, "C Programming");
strcpy( Book1.author, "Nuha Ali");
strcpy( Book1.subject, "C Programming Tutorial");
Book1.book_id = 6495407;
/* book 2 specification */
strcpy( Book2.title, "Telecom Billing");
strcpy( Book2.author, "Zara Ali");
strcpy( Book2.subject, "Telecom Billing Tutorial");
Book2.book_id = 6495700;
Example using function and pointer:
11
/* print Book1 info by passing address of Book1 */
printBook( &Book1 );
/* print Book2 info by passing address of Book2 */
printBook( &Book2 );
return 0;
}
void printBook( struct Books *book ) {
printf( "Book title : %sn", book->title);
printf( "Book author : %sn", book->author);
printf( "Book subject : %sn", book->subject);
printf( "Book book_id : %dn", book->book_id);
}
Book title : C Programming
Book author : Nuha Ali
Book subject : C Programming Tutorial
Book book_id : 6495407
Book title : Telecom Billing
Book author : Zara Ali
Book subject : Telecom Billing Tutorial
Book book_id : 6495700
OUTPUT
12

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Structure in c language
Structure in c languageStructure in c language
Structure in c language
 
Structure in c
Structure in cStructure in c
Structure in c
 
Data types in C
Data types in CData types in C
Data types in C
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Structure in c
Structure in cStructure in c
Structure in c
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
Structure in C
Structure in CStructure in C
Structure in C
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
 
Structures
StructuresStructures
Structures
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
String functions in C
String functions in CString functions in C
String functions in C
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 

Andere mochten auch

C programming-apurbo datta
C programming-apurbo dattaC programming-apurbo datta
C programming-apurbo dattaApurbo Datta
 
C programing basic input and output
C  programing basic input and outputC  programing basic input and output
C programing basic input and outputdhanajeyan dhanaj
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGAbhishek Dwivedi
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
C programing Technical interview
C programing  Technical interview C programing  Technical interview
C programing Technical interview Vishnu Teraiya
 
C Programing Solve Presentation -CSE
C Programing Solve Presentation -CSEC Programing Solve Presentation -CSE
C Programing Solve Presentation -CSEsalman ahmed
 
Phần 10: Dữ liệu kiểu cấu trúc
Phần 10: Dữ liệu kiểu cấu trúcPhần 10: Dữ liệu kiểu cấu trúc
Phần 10: Dữ liệu kiểu cấu trúcHuy Rùa
 
Object Oriented Programing in JavaScript
Object Oriented Programing in JavaScriptObject Oriented Programing in JavaScript
Object Oriented Programing in JavaScriptAkshay Mathur
 
C language control statements
C language  control statementsC language  control statements
C language control statementssuman Aggarwal
 
ppt on linux by MUKESH PATEL
ppt on linux by MUKESH PATELppt on linux by MUKESH PATEL
ppt on linux by MUKESH PATELneo_patel
 
Lập trình c++ có lời giải 2
Lập trình c++ có lời giải 2Lập trình c++ có lời giải 2
Lập trình c++ có lời giải 2Minh Ngoc Tran
 
Presentation1 linux os
Presentation1 linux osPresentation1 linux os
Presentation1 linux osjoycoronado
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorialalexjones89
 

Andere mochten auch (20)

C programming-apurbo datta
C programming-apurbo dattaC programming-apurbo datta
C programming-apurbo datta
 
C programing basic input and output
C  programing basic input and outputC  programing basic input and output
C programing basic input and output
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
C language ppt
C language pptC language ppt
C language ppt
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
C programing Technical interview
C programing  Technical interview C programing  Technical interview
C programing Technical interview
 
C Programing Solve Presentation -CSE
C Programing Solve Presentation -CSEC Programing Solve Presentation -CSE
C Programing Solve Presentation -CSE
 
Phần 10: Dữ liệu kiểu cấu trúc
Phần 10: Dữ liệu kiểu cấu trúcPhần 10: Dữ liệu kiểu cấu trúc
Phần 10: Dữ liệu kiểu cấu trúc
 
Ch10
Ch10Ch10
Ch10
 
Object Oriented Programing in JavaScript
Object Oriented Programing in JavaScriptObject Oriented Programing in JavaScript
Object Oriented Programing in JavaScript
 
C language control statements
C language  control statementsC language  control statements
C language control statements
 
ppt on linux by MUKESH PATEL
ppt on linux by MUKESH PATELppt on linux by MUKESH PATEL
ppt on linux by MUKESH PATEL
 
Lập trình c++ có lời giải 2
Lập trình c++ có lời giải 2Lập trình c++ có lời giải 2
Lập trình c++ có lời giải 2
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
 
Loops in C
Loops in CLoops in C
Loops in C
 
Presentation1 linux os
Presentation1 linux osPresentation1 linux os
Presentation1 linux os
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
 

Ähnlich wie C programing -Structure

Ähnlich wie C programing -Structure (20)

Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
 
Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
 
Structure prespentation
Structure prespentation Structure prespentation
Structure prespentation
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
 
Chapter 13.1.9
Chapter 13.1.9Chapter 13.1.9
Chapter 13.1.9
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdfSTRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
STRUCTURE AND UNION IN C MRS.SOWMYA JYOTHI.pdf
 
C structure and union
C structure and unionC structure and union
C structure and union
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Structures
StructuresStructures
Structures
 
Programming in C session 3
Programming in C session 3Programming in C session 3
Programming in C session 3
 
Structure and Typedef
Structure and TypedefStructure and Typedef
Structure and Typedef
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
structure and union1.pdf
structure and union1.pdfstructure and union1.pdf
structure and union1.pdf
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Str
StrStr
Str
 
Chapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptxChapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptx
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
 

Kürzlich hochgeladen

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 

Kürzlich hochgeladen (20)

Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 

C programing -Structure

  • 2. Contents:  Introduction  Syntax and formation  Variables and member accessing  Nesting of structures  Use of function and pointer in structure 2
  • 3. Intro:  Structure is another user defined data type like array available in C , that allows to combine data items of different kinds of data types, whereas arrays allow only of same data type .  Structures are used to represent a record. Suppose you want to keep track of your books in a library. You might want to track the following attributes about each book − Title − Author − Subject − Book ID 3 All these data can be saved under a single name in STRUCTURE
  • 4. Structure declarations 4 To define a structure, you 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 [structure tag] { member definition; member definition; ... member definition; } [one or more structure variables]; struct person { char name[50]; int cit_no; float salary; }; We can create the structure for a person as mentioned above as:
  • 5. Structure variable declaration 5 When a structure is defined, it creates a user-defined type but, no storage is allocated. For the above structure of person, variable can be declared as: struct person { char name[50]; int cit_no; float salary; }; Inside main function: struct person p1, p2, p[20]; Another way of creating sturcture variable is: struct person { char name[50]; int cit_no; float salary; }p1 ,p2 ,p[20];
  • 6. Member access 6 Accessing members of a structure There are two types of operators used for accessing members of a structure. 1. Member operator(.) 2. Structure pointer operator(->) Any member of a structure can be accessed as: structure_variable_name.member_name Suppose, we want to access salary for variable p2. Then, it can be accessed as: p2.salary
  • 7. Nested Structures 7 Structures can be nested within other structures in C programming. struct complex { int imag_value; float real_value; }; struct number{ struct complex c1; int real; }n1,n2; Suppose you want to access imag_value for n2 structure variable then, structure member n1.c1.imag_value is used.
  • 8. Sample program CS 3090: Safety Critical Programming in C 8
  • 9. Pointers to Structure : 9 We can define pointers to structures in the same way as we define pointer to any other variable − struct Books *struct_pointer; Now, we can store the address of a structure variable in the above defined pointer variable. To find the address of a structure variable, place the '&'; operator before the structure's name as follows − struct_pointer = &Book1; To access the members of a structure using a pointer to that structure, you must use the -> operator as follows − struct_pointer->title;
  • 10. Example using function and pointer: 10 #include <stdio.h> #include <string.h> struct Books { char title[50]; char author[50]; char subject[100]; int book_id; }; /* function declaration */ void printBook( struct Books *book ); int main( ) { struct Books Book1; /* Declare Book1 of type Book */ struct Books Book2; /* Declare Book2 of type Book */ /* book 1 specification */ strcpy( Book1.title, "C Programming"); strcpy( Book1.author, "Nuha Ali"); strcpy( Book1.subject, "C Programming Tutorial"); Book1.book_id = 6495407; /* book 2 specification */ strcpy( Book2.title, "Telecom Billing"); strcpy( Book2.author, "Zara Ali"); strcpy( Book2.subject, "Telecom Billing Tutorial"); Book2.book_id = 6495700;
  • 11. Example using function and pointer: 11 /* print Book1 info by passing address of Book1 */ printBook( &Book1 ); /* print Book2 info by passing address of Book2 */ printBook( &Book2 ); return 0; } void printBook( struct Books *book ) { printf( "Book title : %sn", book->title); printf( "Book author : %sn", book->author); printf( "Book subject : %sn", book->subject); printf( "Book book_id : %dn", book->book_id); } Book title : C Programming Book author : Nuha Ali Book subject : C Programming Tutorial Book book_id : 6495407 Book title : Telecom Billing Book author : Zara Ali Book subject : Telecom Billing Tutorial Book book_id : 6495700 OUTPUT
  • 12. 12