
- Go Tutorial
- Go - Home
- Go - Overview
- Go - Environment Setup
- Go - Program Structure
- Go - Basic Syntax
- Go - Data Types
- Go - Variables
- Go - Constants
- Go - Operators
- Go - Decision Making
- Go - Loops
- Go - Functions
- Go - Scope Rules
- Go - Strings
- Go - Arrays
- Go - Pointers
- Go - Structures
- Go - Slice
- Go - Range
- Go - Maps
- Go - Recursion
- Go - Type Casting
- Go - Interfaces
- Go - Error Handling
- Go Useful Resources
- Go - Questions and Answers
- Go - Quick Guide
- Go - Useful Resources
- Go - Discussion
Go - Miscellaneous Operators
There are a few other important operators supported by Go Language including sizeof and ?:.
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. |
Example
Try following example to understand all the miscellaneous operators available in Go programming language −
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); }
When you compile and execute the above program it produces the following result −
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.
go_operators.htm
Advertisements