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 7856819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:49:45+00:00 2026-06-02T20:49:45+00:00

I need to declare an array of structures on the heap, then transfer data

  • 0

I need to declare an array of structures on the heap, then transfer data from parallel arrays on the stack and from calculations into each structure. I declared

struct Grades
{
    string  studentName;
    int     scores[4];
    double  average;
};

....

Grades *art1301 = new Grades;

....

(art1301 + i)->studentName = names[i];

for((int i = 0 ; i < 5 ; i++ )
(art1301 + i)->scores[j] = exams[i][j];

(art1301 + i)->average = average; 

My program accesses the first record, but it crashes after it accesses the first field of the second record. I don’t understand why it works for the first record, but dies in the middle of the second? Am I accessing the structure correctly?

Thank you.

  • 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-06-02T20:49:46+00:00Added an answer on June 2, 2026 at 8:49 pm

    To allocate an array, you need the array form of new, with the square brackets:

    Grades *art1301 = new Grades[200];
    //                          ^^^^^
    

    The array size can be a dynamically determined quantity.

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

Sidebar

Related Questions

Possible Duplicate: Very large array on the heap (Visual C++) i need to declare
I'm reading data from a file that I need to be put into my
I need to declare 3d array variable but can't. int[][][] ary = new int[5][2][];
I need to declare an array globally, because I want all methods to be
I'm working on a embedded application where I need to declare an array of
I have a small question. Do i need to declare an array if i
I need to declare an array of pointers to functions like so: extern void
I need to declare a boost::array. I did it as boost::array<char, 116> buf; is
I need to declare a global two-dimensional array in C. The size of the
I need to declare an array that consists of different variable types, mainly: char

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.