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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:25:28+00:00 2026-06-03T14:25:28+00:00

for instance this code: struct test{ int ID; bool start; }; struct test *

  • 0

for instance this code:

struct test{
    int ID;
    bool start;
};

struct test * sTest;

void changePointer(struct test * t)
{
    t->ID = 3;
    t->start = false;    
}

int main(void)
{
    sTest->ID = 5;
    sTest->start = true;
    changePointer(sTest);
    return 0;
}

If I was to execute this code, then what would the output be? (i.e. if I pass a pointer like this, does it change the reference or is it just a copy?)

Thanks in advance!

  • 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-03T14:25:30+00:00Added an answer on June 3, 2026 at 2:25 pm

    Your program doesn’t have any output, so there would be none.

    It also never initializes the sTest pointer to point at some valid memory, so the results are totally undefined. This program invokes undefined behavior, and should/might/could crash when run.

    IF the pointer had been initialized to point at a valid object of type struct test, the fields of that structure would have been changed so that at the end of main(), ID would be 3. The changes done inside changePointer() are done on the same memory as the changes done in main().

    An easy fix would be:

    int main(void)
    {
       struct test aTest;
       sTest = &aTest;    /* Notice the ampersand! */
       sTest->start = true;
       changePointer(sTest);
    
       return 0;
    }
    

    Also note that C before C99 doesn’t have a true keyword.

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

Sidebar

Related Questions

I've got this sample code: struct A { int foo() { return 27; }
Given this simple C code: struct { struct a { int foo; }; struct
I have this code : public struct SmartFilter { public int from, to; public
My understanding is nothing will happen. For instance this code: foreach (var some in
How to get generic interface type for an instance ? Suppose this code: interface
This is my svg code for instance. <rect x=1531.718 y=1688.217 opacity=0.8 fill=#FEE880 enable-background=new width=40.67
If I create a SslStream instance like this: secureStream = new SslStream(stream, true, tlsRemoteCallback,
Example: public bool Save(MyObj instance) { if (instance.IsNew) { this.repository.Create(instance); } else { this.repository.Update(instance);
Setup Given this user-defined type: struct T { static int x; int y; T()
Given the following contrived example code: struct abc { int x[5]; int y[5]; };

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.