Go-misc-operator

提供:Dev Guides
移動先:案内検索

Go-その他の演算子

*sizeof* や*?:。*など、Go言語でサポートされている他の重要な演算子がいくつかあります
Operator Description Example
& Returns the address of a variable. &a; provides actual address of the variable.
* Pointer to a variable. *a; provides pointer to a variable.

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.