To add two numbers in Go, you can create two variables and assign values to them, then use the +
arithmetic operator to add them together. Here's an example code snippet:
main.go177 chars11 lines
In this example, we create two variables num1
and num2
, and assign the values 5
and 10
to them, respectively. We then create another variable sum
and use the +
operator to add num1
and num2
together, assigning the result to sum
. Finally, we use the Println()
function from the fmt
package to print out the sum to the console. Running this code will output:
main.go26 chars2 lines
gistlibby LogSnag