What Is Structure ?
The structure is a user-defined data type in C++. The structure is used to represent a record. Suppose you want to store a record of Student which consists of student name, address, roll number and age. You can define a structure to hold this information.
Defining a structure
struct keyword is used to define a structure. struct define a new data type which is a collection of different type of data.
Syntax:-
struct structure_name
{
//Statements
};
Logic:-
Here we are storing a book's information like Title, Publication. here in the structure block book title and publication define a string and year and status is an integer. see the below block for better understanding.
Structure Block
struct books
{
char title[25];
char pub[25];
int year;
int status;
};
Output:
Enter Number Of Books :3
-------------------------
Enter The Book Details :
Title java
Publication gorgea
Year 2013
Status outdated
-------------------------
Enter The Book Details :
Title python
Publication nasifk
Year 2017
Status medium
-------------------------
Enter The Book Details :
Title programming
Publication boundy
Year 2011
Status lates
-------------------------
=====================================================
Book Title |Publication |Year |Status
java gorgea 2013 outdated
python nasifk 2017 medium
programming boundy 2011 lates
=====================================================
=================================================
need an explanation for this answer? contact us directly to get an explanation for this answer