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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:12:19+00:00 2026-06-14T20:12:19+00:00

Having some concerns about the functionality of the member reference and pointer operators.. Take

  • 0

Having some concerns about the functionality of the member reference and pointer operators..

Take the following example:

struct ID{
    uint8_t index;
    bool active;
}

struct Square{
    struct ID shortID;
    struct BUDDY *bud;
    uint8_t x;
    uint8_t y;
};

And then I later return a pointer to a square..
My question is: Can I then modify members of ID and have the changes reflected in the nested struct?

void function1()
{
    Square *someSquare = GetSquare(1);
    someSquare->shortID.index = 89; // Is this now reflected everywhere? OR was the shortID struct only modified in the scope of this funciton..
}

void function2()
{
    Square *someSquare = GetSquare(1);
    if ( someSquare->shortID.index != 89 )
    {
        // Dang...
    }
}

Thanks!

EDIT:

Thanks for the concise answers, yes the GetSquare function returns a pointer to the specified index of an array of squares. Like so:

Square* GetSquare( uint8_t index )
{
    return &squares[index];  
}

So the instance should be the same every time, as the “squares” array is allocated once on object creation. So thank you for your insight my problem must be elsewhere in my code 🙂

  • 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-14T20:12:20+00:00Added an answer on June 14, 2026 at 8:12 pm

    yes because someSquare is a Square*
    the -> operator is like a (*varname). .
    So it is the content of the pointer and you get the type Square.
    Then you can just modify the variable with . , because its a struct and all variables are public not like it could be in classes.

    The Changes you made in function1 can be seen in function2 if the GetSquare returns the same object that could be the case if your GetSquare looks like this.

    Square * GetSquare(int i)
    {
        static Square * pSquare = 0;
        if (pSquare)
            pSquare = malloc(sizeof(static Square));
        return pSquare;
    }
    

    or for global variables like this

    static Square pSquare ;
    
    Square * GetSquare(int i)
    {
        return &pSquare;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently, I found myself having to write up some concerns I have about race
Having some annoying issues with loading images into a BufferedImage (image in the example)
Having some trouble with what should be a very simple scenario. For example purposes,
We're about to set off our first larger WCF project, and we're having some
In talking at work about possible solutions to some problems we are having in
Having some trouble with R's garbage collection, when passing objects to C++. We have
Having some trouble getting a screenscraper webservice up and running on a weblogic 10.3.3
Having some issues getting my head around the differences between UTF-8, UTF-16, ASCII and
Having some issues with the ... in ObjectiveC. I'm basically wrapping a method and
Am having some trouble with the SkyDrive download process and hoping you can help

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.