Algorithm


  1. 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:

    1. 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
       
  2. 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 */
     

 

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

x
+
cmd
Age is 25

#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

x
+
cmd
Salary: 30000

#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

x
+
cmd
Age is 25
Advertisements

Demonstration


Go Comments-Go Long Programmimg