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

  • Home
  • SEARCH
  • 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 8500703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:00:56+00:00 2026-06-11T01:00:56+00:00

I’m really new to C programming and I’m still trying to understand the concept

  • 0

I’m really new to C programming and I’m still trying to understand the concept of using pointers and using typedef structs.

I have this code snippet below that I need to use in a program:

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

I’m not exactly sure what this does – to me it seems similar as using interfaces in Objective-C, but I don’t think that’s the case.

And then I have this line

pStudentRecord* g_ppRecords;

I basically need to add several pStudentRecord to g_ppRecords based on a number. I understand how to create and allocate memory for an object of type pStudentRecord, but I’m not sure how to actually add multiple objects to g_ppRecords.

  • 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-11T01:00:57+00:00Added an answer on June 11, 2026 at 1:00 am

    A struct is a compound data type, meaning that it’s a variable which contains other variables. You’re familiar with Objective C, so you might think of it as being a tiny bit like a ‘data only’ class; that is, a class with no methods. It’s a way to store related information together that you can pass around as a single unit.

    Typedef is a way for you to name your own data types as synonyms for the built-in types in C. It makes code more readable and allows the compiler to catch more errors (you’re effectively teaching the compiler more about your program’s intent.) The classic example is

    typedef int BOOL;
    

    (There’s no built-in BOOL type in older ANSI C.)

    This means you can now do things like:

    BOOL state = 1;
    

    and declare functions that take BOOL parameters, then have the compiler make sure you’re passing BOOLs even though they’re really just ints:

    void flipSwitch(BOOL isOn); /* function declaration */
    ...
    int value = 0;
    BOOL boolValue = 1;
    flipSwitch(value); /* Compiler will error here */
    flipSwitch(boolValue); /* But this is OK */
    

    So your typedef above is creating a synonym for a student record struct, so you can pass around student records without having to call them struct StudentRecord every time. It makes for cleaner and more readable code. Except that there’s more to it here, in your example. What I’ve just described is:

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

    You can now do things like:

    StudentRecord aStudent = { "Angus\n", "Young\n", 1, 4.0 };
    

    or

    void writeToParents(StudentRecord student) {
        ...
    }
    

    But you’ve got a * after the typedef. That’s because you want to typedef a data type which holds a pointer to a StudentRecord, not typedef the StudentRecord itself. Eh? Read on…

    You need this pointer to StudentRecord because if you want to pass StudentRecords around and be able to modify their member variables, you need to pass around pointers to them, not the variables themselves. typedefs are great for this because, again, the compiler can catch subtle errors. Above we made writeToParents which just reads the contents of the StudentRecord. Say we want to change their grade; we can’t set up a function with a simple StudentRecord parameter because we can’t change the members directly. So, we need a pointer:

    void changeGrade(StudentRecord *student, float newGrade) {
      student->mark = newGrade;
    }
    

    Easy to see that you might miss the *, so instead, typedef a pointer type for StudentRecord and the compiler will help:

    typedef struct { /* as above */ } *PStudentRecord;
    

    Now:

    void changeGrade(PStudentRecord student, float newGrade) {
      student->mark = newGrade;
    }
    

    It’s more common to declare both at the same time:

    typedef struct {
      /* Members */
    } StudentRecord, *PStudentRecord;
    

    This gives you both the plain struct typedef and a pointer typedef too.

    What’s a pointer, then? A variable which holds the address in memory of another variable. Sounds simple; it is, on the face of it, but it gets very subtle and involved very quickly. Try this tutorial

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.