切片声明中的var和:=的区别在于语言

i have recently started working on go and was wondering with few of the ways to declare an slice

  1. Without var -

p := []int{}

  1. With var

var p = []int{}

Here are the two programs

First One

package main

import "fmt"

func main() {
    p := []int{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}
    for i, v := range p {
        fmt.Println(i, v)
    }
}

Second One

package main

import "fmt"

func main() {
    var p = []int{1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024}
    for i, v := range p {
        fmt.Println(i, v)
    }
}

What's the primary difference in both the programs compilation, memory allocation and runtime ?

What's the primary difference in both the programs compilation, memory allocation and runtime ?

None.

(Note that there is also no secondary difference.)

The best advice for such questions is: Consult the language specification.