12. Structure in C++ | IndianTechnoEra - IndianTechnoEra
Latest update Android YouTube

12. Structure in C++ | IndianTechnoEra

Structure in c++
Admin

The structure is a collection of dissimilar data types.

Structure in C++  | it2Edu

Declaration of structure doesn’t reserve memory, it is only reserved when variables of structure data types are created.

Syntax :

struct structure_name
{
    //variable declaration
};

Eaxmple :

#include<iostream>
using namespace std;
//structure
struct bookDetails
{
    char name;
    int pages;
    float price;
};
//main declaration
int main()
{
    struct bookDetails b;
    cout<<"Enter name of book : \n";
    cin>>b.name;
    cout<<"\nEnter number of pages in book : \n";
    cin>>b.pages;
    cout<<"\nEnter price of book : \n";
    cin>>b.price;
    cout<<"\nDetails of book is : \n";
    cout<<"\nbook name : "<<b.name;
    cout<<"\nnumber of pages : "<<b.pages;
    cout<<"\nprice of book : "<<b.price;
}

Output :

Enter No Of Books : 1
Enter the book details
Details of Book Number : 1
Book Name separate it by underscore : harry_potter
Book Author :j.k.rowling

S.NoBook NameAuthor
1harry_potterj.k.rowling


NOTE: Structure declaration must end with a semicolon.



Post a Comment

Feel free to ask your query...
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.