Go Programming Language Comments

Go Programming Language Comments

Comment is used to explain how to work on the code.

To write the comment in the code, we can use // and /* */ syntax.

Single line comment

// syntax is used to write the single line comment in the code.

// declare variables
Var name = “name1”

Multiple line comment

/* */ syntax is used to write the multiple line comment in the code.

/* print the result 
and variables value in a line. */
fmt.Println("name: ", name)                                            	 
fmt.Println("id: ", id)                                                	 
fmt.Println("salary: ", salary)      

Go Comment Example

package main                                                               	 
                                                                           	 
import "fmt"                                                               	 
                                                                           	 
                                                                           	 
func main() {                                                              	 
	// declare variables                                                   	 
	var name string                                                        	 
	var id int                                                             	 
	var salary float32                                                     	 
                                                                           	 
	// assign values                                                       	 
	name = "name1"                                                         	 
	id = 10                                                                	 
	salary = 25000.500                                                     	 
                                                                           	 
	/* prints the variables                                                	 
	in a line */                                                                           	 
	fmt.Println("name: ", name)                                            	 
	fmt.Println("id: ", id)                                                	 
	fmt.Println("salary: ", salary)                                        	 
                                                                           	 
}
Output:
]$ go build comments.go
$ ./comments
name:  name1
id:  10
salary:  25000.5