Go Comments
In Go programming, comments are used to improve the readability of the program. The comments are ignored by the Go compiler, and hence not compiled or transformed to low level code.
In Go programming, we can provide single line comments or multi line comments.
Go Single Line Comments
To write single line comments in golang, use double slash at the beginning of the comment // comment
. In the following example, we have written single line comments.
example.go
</>
Copy
package main
import "fmt"
func main() {
// this is a single line comment
fmt.Println("Hello World")
// this is another comment
}
Go Multiline Comments
To write multi line comments in golang, enclose the comment lines in /* comment(s) */
. In the following example, we have written multi line comments.
example.go
</>
Copy
package main
import "fmt"
func main() {
/* this is a multi line comment
this is another line in the same comment
*/
fmt.Println("Hello World")
}
Conclusion
In this Golang Tutorial, we learned how to write single line comments and multiple line comments.