2.33. Go language pointer array

发布时间 :2023-10-12 23:00:09 UTC      

Before we look at the pointer array, let’s take a look at an example that defines an integer array of length 3:

2.33.1. Example #

package main
import "fmt"
const MAX int = 3
func main() {
   a := []int{10,100,200}
   var i int
   for i = 0; i < MAX; i++ {
      fmt.Printf("a[%d] = %d\\n", i, a[i] )
   }
}

The output of the above code execution is as follows:

a[0] = 10
a[1] = 100
a[2] = 200

In one case, we may need to save the array so that we need to use the pointer.

The following declares an array of integer pointers:

var ptr [MAX]*int;

ptr is an array of integer pointers. So each element points to a value. Three integers for the following examples are stored in an array of pointers:

2.33.2. Example #

package main
import "fmt"
const MAX int = 3
func main() {
   a := []int{10,100,200}
   var i int
   var ptr [MAX]*int;
   for  i = 0; i < MAX; i++ {
      ptr[i] = &a[i] /* Assigning an integer address to a pointer array */
   }
   for  i = 0; i < MAX; i++ {
      fmt.Printf("a[%d] = %d\\n", i,*ptr[i] )
   }
}

The output of the above code execution is as follows:

a[0] = 10
a[1] = 100
a[2] = 200

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.