pointers to structures(structs)


#include<iostream>
using namespace std;
#include<string>

int main(){
struct codes{
int isbn;
string description;
};
struct abc{//structure template
struct codes handle;
string author;
string book;
float price;
};
  
struct abc libry[2]={{{1213,"magical book"},"J K ROWLING ","HArry Potter",23.21},{{12132,"fantasy"},"William Hayt","engineering circuit",23.1}};// declare libry variable that will contain 5 records

struct abc *point;
point=&libry[0];

cout<<"address of first member of struct abc = "<<point<<endl;
cout<<(*point).book<<"was written by "<<(*point).author<<" and its isbn = "<<(*point).handle.isbn<<"and its pprice = "<<(*point).price
<<"and the book is about "<<(*point).handle.description<<endl<<endl;
cout<<"now for member 2 of struct "<<endl;

point++;

cout<<"address of second member of struct abc = "<<point<<endl;

cout<<(*point).book<<"was written by "<<(*point).author<<" and its isbn = "<<(*point).handle.isbn<<"and its pprice = "<<(*point).price
<<"and the book is about "<<(*point).handle.description<<endl<<endl;

}





Previous
Next Post »

Comments:

Disqus Shortname