Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 844745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:20:10+00:00 2026-05-15T06:20:10+00:00

I’m studying C++ from Schildt’s book and don’t quite understand what does he mean

  • 0

I’m studying C++ from Schildt’s book and don’t quite understand what does he mean under third structure; Can somebody explain this ->

To access a specific structure within
an array of structures, you must index
the structure name. For example, to
display the on_hand member of the
third structure, you would write
cout << invtry[2].on_hand;

Some code:

struct type{
 char item[40];
 double cost;
 double retail;
 int on_hand;
 int lead_time;
}invtry[SIZE];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:20:11+00:00Added an answer on May 15, 2026 at 6:20 am

    The third structure in an array of structures is the one placed in the third position in the array, i.e., the one with index 2.

    In your (ugly) code, invtry is declared as an array (of size SIZE) of structures of type type. Hence invtry[0] is the first element, invtry[1] the second, and invtry[2] the third – assuming, of course, SIZE >= 3.


    Normally, you would write:

    struct type{
     char item[40];
     double cost;
     double retail;
     int on_hand;
     int lead_time;
    };
    
    const int SIZE = 500;
    
    type invtry[SIZE];
    

    This is synonymous to what you wrote, except for the definition of SIZE of course. But it leads to less confusion – in one part you say what a type (terrible name for the struct!) is – in other words, you define the type type. Later, you create an array of structs of type type, called invtry.

    Doing this in the same line, as the author did, is simply awful – to my eyes.

    Now you have an array of 500 structs. If “type” was “Product”, you would have an array representing 500 products. Each one with its item, cost, retail, etc.

    To access the third struct in the array, write invtry[2]. to access its particular on_hand field, write invtry[2].on_hand. This has nothing to do with the specific position of on_hand in the layout of the defined type.

    If you want the lead_time of the third structure, first access the third structure and then its lead_time member: invtry[2].lead_time.

    Of course since type does not have a default (parameterless) constructor, the 500 products are uninitialized – you have garbage in them. But that is your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.