Algorithm
-
In Go, comments are used to annotate the code with explanatory information for developers or to disable certain parts of the code temporarily. There are two types of comments in Go:
-
Single-line Comments:
- Single-line comments start with
//
. - Anything following
//
on that line is treated as a comment.
go
// This is a single-line comment var x int // This is also a comment
- Single-line comments start with
-
-
Multi-line Comments:
- Multi-line comments start with
/*
and end with*/
. - Anything between
/*
and*/
is treated as a comment.
go
/* This is a multi-line comment */
- Multi-line comments start with
Code Examples
#1 Single Line Comment in Go lang Programming
Code -
Golang Programming
package main
import "fmt"
func main() {
// declare a variable
age := 25
// print the variable
fmt.Println("Age is", age)
}
Copy The Code &
Try With Live Editor
Output
#2 Multiline Comments in Go lang Programming
Code -
Golang Programming
package main
import "fmt"
func main() {
/* creates a variable
to store the salary of the employee
*/
salary := 30000
fmt.Println("Salary:", salary)
}
Copy The Code &
Try With Live Editor
Output
#3 Go Comments for Example Code
Code -
Golang Programming
package main
import "fmt"
func main() {
age := 25
height := 170
fmt.Println("Age is", age)
}
Copy The Code &
Try With Live Editor
#4 Go Comments for Example Code
Code -
Golang Programming
package main
import "fmt"
func main() {
age := 25
// height := 170
fmt.Println("Age is", age)
}
Copy The Code &
Try With Live Editor
Output
Demonstration
Go Comments-Go Long Programmimg