目录

Show 例子

Go语言支持其他一些重要的运算符,包括sizeof?:.

操作者 描述
& 返回变量的地址。 &一个; 提供变量的实际地址。
*Pointer to a variable. *一个; 提供指向变量的指针。

例子 (Example)

尝试以下示例来了解Go编程语言中可用的所有其他运算符 -

package main
import "fmt"
func main() {
   var a int = 4
   var b int32
   var c float32
   var ptr *int
   /* example of type operator */
   fmt.Printf("Line 1 - Type of variable a = %T\n", a );
   fmt.Printf("Line 2 - Type of variable b = %T\n", b );
   fmt.Printf("Line 3 - Type of variable c= %T\n", c );
   /* example of & and * operators */
   ptr = &a	/* 'ptr' now contains the address of 'a'*/
   fmt.Printf("value of a is  %d\n", a);
   fmt.Printf("*ptr is %d.\n", *ptr);
}

编译并执行上述程序时,会产生以下结果 -

Line 1 - Type of variable a = int
Line 2 - Type of variable b = int32
Line 3 - Type of variable c= float32
value of a is  4
*ptr is 4.
↑回到顶部↑
WIKI教程 @2018