Showing posts with label What is structure. Show all posts
Showing posts with label What is structure. Show all posts

Sunday, 24 September 2017

What is c++ structure

Structures


Struture is collection of diffrent data type of variable.Struture is way to create variables and we create member.struture same as class.

Structures are variables which have several types; each type of the object can have different types.
Each type of the structure is called a member of the structure.

how to declare a sruture in c++ programming

struct keyword through we define struture name (structure name as identifier)

example...

struct book
{
int bookid;
char title[30];
float price;
};
A structure data type called Book can hold all this information:

struct book{

int bookid;
char title[30];
float price;

};

before the final semicolon, At the end of the structure's definition, we can define one or more structure variables.

There is also another way of declaring variables given below,
struct student s1;

# Initialization
Structure members can be initialized at declaration. This is same as the initialization of arrays; the values are listed inside braces. The structure declaration is preceded by the keyword static.

static struct book b1 ={11,''java'',20,345.45};

how to access member of structure?

To access a given member the dot notation is use. The ''dot'' is called the member access operator

struct book b1;
b1.bookid = 11;
b1.title = "java"
b1.price = n345.45

example c++ structure

#include<iostream.h>
#include<conio.h>
struct book
{

          int bookid;
         char title[30];
         float price;

};
void main()
{
book b1;
     
        cout <<  "Please Enter the book id';
        cin >> b1.bookid << endle;
        cout <<  "Please Enter the book title';
        cin >> b1.title << endle;
        cout <<  "Please Enter the book price';
        cin >> b1.price << endle;
       
        cout << "\n Display the book record." << endle;
        cout << "book id"b1.booidid;
         cout << "title"b1.title;
         cout << "price"b1.price;
      
      getch();
       }

    Output
-------------------------------------------------------
Display the book record.

 Book id  = 11
 Title       = jave
 Price      =345.45