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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:40:49+00:00 2026-06-11T10:40:49+00:00

I have to use the following block of code for a school assignment, STRICTLY

  • 0

I have to use the following block of code for a school assignment, STRICTLY WITHOUT ANY MODIFICATIONS.

typedef struct 
{
    char* firstName;
    char* lastName;
    int id;
    float mark;
}* pStudentRecord;

pStudentRecord* g_ppRecords;
int g_numRecords =0;

Here g_ppRecords is supposed to be an array of pointers to structs. What I am completely failing to understand is that how can the statement pStudentRecords *g_ppRecords; mean g_ppRecords to be an array because an array should be defined as

type arrayname[size];

I tried allocating memory to g_ppRecords dynamically, but that’s not helping.

g_ppRecords = (pStudentRecord*) malloc(sizeof(pStudentRecord*)*(g_numRecords+1));
  • 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-11T10:40:51+00:00Added an answer on June 11, 2026 at 10:40 am

    Observe that pStudentRecord is typedef’d as a pointer to a structure. Pointers in C simply point to the start of a memory block, whether that block contains 1 element (a normal “scalar” pointer) or 10 elements (an “array” pointer). So, for example, the following

    char c = 'x';
    char *pc = &c;
    

    makes pc point to a piece of memory that starts with the character 'x', while the following

    char *s = "abcd";
    

    makes s point to a piece of memory that starts with "abcd" (and followed by a null byte). The types are the same, but they might be used for different purposes.

    Therefore, once allocated, I could access the elements of g_ppRecords by doing e.g. g_ppRecords[1]->firstName.

    Now, to allocate this array: you want to use g_ppRecords = malloc(sizeof(pStudentRecord)*(g_numRecords+1)); (though note that sizeof(pStudentRecord*) and sizeof(pStudentRecord) are equal since both are pointer types). This makes an uninitialized array of structure pointers. For each structure pointer in the array, you’d need to give it a value by allocating a new structure. The crux of the problem is how you might allocate a single structure, i.e.

    g_ppRecords[1] = malloc(/* what goes here? */);
    

    Luckily, you can actually dereference pointers in sizeof:

    g_ppRecords[1] = malloc(sizeof(*g_ppRecords[1]));
    

    Note that sizeof is a compiler construct. Even if g_ppRecords[1] is not a valid pointer, the type is still valid, and so the compiler will compute the correct size.

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

Sidebar

Related Questions

I have tried to use the following snippet of code: int main() { string
I have an array of objects, and i use following code to get in
I have use following code to display category and there product on click patent
In my CMS contact-us page, I have the following code: {{block type=core/template name=contactForm form_action=/contacts/index/post
I have a code block that I use for running a piece of code
So I have the following code block: var sw = new Stopwatch(); sw.Start(); while
I have the following block of code in a jQTouch app I'm working on:
I have following use-case: there are several assemblies decorated with ProtoContract classes and I
i have to use the following function, to change the input's type <input class=input
I find that I have to use the following style to specify a style

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.