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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:39:42+00:00 2026-06-15T15:39:42+00:00

Per the Go tour page 28 and page 53 They show a variable that

  • 0

Per the Go tour page 28 and page 53

They show a variable that is a pointer to a struct literal. Why is this not the default behavior? I’m unfamiliar with C, so it’s hard to wrap my head around it. The only time I can see when it might not be more beneficial to use a pointer is when the struct literal is unique, and won’t be in use for the rest program and so you would want it to be garbage collected as soon as possible. I’m not even sure if a modern language like Go even works that way.

My question is this. When should I assign a pointer to a struct literal to a variable, and when should I assign the struct literal itself?

Thanks.

  • 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-15T15:39:43+00:00Added an answer on June 15, 2026 at 3:39 pm

    Using a pointer instead of just a struct literal is helpful when

    • the struct is big and you pass it around
    • you want to share it, that is that all modifications affect your struct instead of affecting a copy

    In other cases, it’s fine to simply use the struct literal. For a small struct, you can think about the question just as using an int or an *int : most of the times the int is fine but sometimes you pass a pointer so that the receiver can modify your int variable.

    In the Go tour exercises you link to, the Vertex struct is small and has about the same semantic than any number. In my opinion it would have been fine to use it as struct directly and to define the Scaled function in #53 like this :

    func (v Vertex) Scaled(f float64) Vertex {
        v.X = v.X * f
        v.Y = v.Y * f
        return v
    }
    

    because having

    v2 := v1.Scaled(5)
    

    would create a new vertex just like

    var f2 float32 = f1 * 5
    

    creates a new float.

    This is similar to how is handled the standard Time struct (defined here), which is usually kept in variables of type Time and not *Time.

    But there is no definite rule and, depending on the use, I could very well have kept both Scale and Scaled.

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

Sidebar

Related Questions

Per different user mode, some pages should not be accessible by users unless they
Per MSDN , In SQL Server, the page size is 8 KB. This means
Per the new profile/fan page tab rule that eliminates the iFrame option, is there
Per this blog post here ( http://www.david-lewis.com/css/css-that-can-affect-performance-on-ipad-web-apps-or-phonegap/ ), there is a bug in iOS
Per a client's request I have written a communication class that inherits from webclient.
Per this question (see comments near the bottom), I was wondering if anyone knows
As per this article : If you try and lock a non-recursive mutex twice
Per the SWIG Documentation (21.9.1 Default primitive type mappings), the C uint8_t is mapped
Per the docs , this should be enough to run Twitter Bootstrap: <div class=carousel>
Per step 3b of this Jetty guide for using Keytool and OpenSSL, last step

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.