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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:24:56+00:00 2026-06-08T18:24:56+00:00

I found myself confused with the array and slice data types. From Go docs,

  • 0

I found myself confused with the array and slice data types.

From Go docs, arrays are described as follows:

There are major differences between the ways arrays work in Go and C. In Go,

  • Arrays are values. Assigning one array to another copies all the elements.
  • In particular, if you pass an array to a function, it will receive a copy of the array, not a pointer to it.
  • The size of an array is part of its type. The types [10]int and [20]int are distinct.

Functions:

As in all languages in the C family, everything in Go is passed by
value. That is, a function always gets a copy of the thing being
passed, as if there were an assignment statement assigning the value
to the parameter. For instance, passing an int value to a function
makes a copy of the int, and passing a pointer value makes a copy of
the pointer, but not the data it points to.

Why does sort.Ints(arrayValue) modify the passed variable when I declared it as an array, not as a slice?

Code

var av = []int{1,5,2,3,7}

fmt.Println(av)
sort.Ints(av)
fmt.Println(av)
return

Output

[1 5 2 3 7]
[1 2 3 5 7]
  • 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-08T18:24:57+00:00Added an answer on June 8, 2026 at 6:24 pm

    See “Slices: usage and internals“

    var av = []int{1,5,2,3,7}
    

    That is a slice, not an array.

    A slice literal is declared just like an array literal, except you leave out the element count.

    That explains why the sort function will modify the content of what is referenced by the slice.

    As commented below by Kirk, sort.Ints will give you an error if you passed it an array instead of a slice.

    func Ints(a []int)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've found myself evaluating both of these libs. Apart from what the GraphicsMagick comparison
I recently found myself writing a piece of code that executed a Core Data
Found myself quite confused today about this. I create a blank repository locally(hg init),
I found myself writing the following a lot: int location =2; vector<int> vec; vector<int>::iterator
I found myself instantiating the same objects in numerous tests, so I'm trying to
So I recently found myself writing a loop similar to this one: var headers
I've found myself recently using the SemaphoreSlim class to limit the work in progress
I have found myself designing a language for fun that is a cross between
I have recently found myself becoming more negative about EF and cannot help wondering
I have found myself doing this in my code to 'cache' the work done

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.