Saturday 28 August 2021

Go Comments

 The Go comments are not executed by the compiler and interpreter. The comments are used to provide information or explanation about the method, variable, class or any statement. It can also be used to hide program code for specific time.

Go Single Line Comment

The double forward slash "//" is used for the single-line comment.

Go Single Line Comment Example:

  1. package main  
  2. import "fmt"  
  3. func main() {  
  4.    var x int = 10 //It is a variable  
  5.    fmt.Print(x)  
  6. }  

Output:

10

Go Multi Line Comment

A multi-line or block-comment starts with /* and ends with */. Here, nesting is not allowed.

Go Multi Line Comment Example:

  1. package main  
  2. import "fmt"  
  3. func main() {  
  4.    var a int = 10  
  5.    /* Let's declare and 
  6.          print variable in Go*/  
  7.    fmt.Printf("value of a is %d \n", a);  
  8. }  

Output:

10


No comments:

Post a Comment