Q:

Golang Basics | Find Output Programs | Set 3

belongs to collection: Golang Find Output Programs

0

This section contains the Golang basics find output programs (set 3) with their output and explanations.

Program 1:

package main

import "fmt"

func main() {
    let var1=10
    let var2=10
    var var3=0
    
    var3 = var1 + var2
    fmt.Println("Sum is: ",var3)
}

 

Program 2:

package main

import "fmt"

func main() {
	const var1 = 10
	const var2 = 10
	var var3 = 0

	var3 = var1 + var2
	fmt.Println("Sum is: ", var3)
}

 

Program 3:

package main

import "fmt"

func main() {
	const var1 = 10
	const var2 = 10
	const var3 = var1 + var2

	fmt.Println("Sum is: ", var3)
}

 

Program 4:

package main
import "fmt"

func main() {
    const var1=10
    const 2var=10
    const var3=var1+2var
    
    fmt.Println("Sum is: ",var3)
}

 

Program 5:

package main

import "fmt"

func main() {
	var num int = 10

	fmt.Print("Enter the value of num: ")
	fmt.scanf("%d", &num)

	fmt.Println("Value of num is: ", num)
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer Program 1:

Output:

./prog.go:6:9: syntax error: unexpected var1 at end of statement
./prog.go:7:9: syntax error: unexpected var2 at end of statement

Explanation:

The above program will generate a syntax error because there is no keyword with the name 'let'.


Answer Program 2:

Output:

Sum is:  20

Explanation:

In the above program, we created two integer constants var1, var2, and one variable var3. Then we calculated the addition and printed the result on the console screen.


 

Answer Program 3:

Output:

Sum is:  20

Explanation:

In the above program, we created three integer constants var1, var2, and var3. Then we the value of var3 on the console screen.


 

Answer Program 4:

Output:

./prog.go:6:11: syntax error: unexpected literal 2, expecting name
./prog.go:6:11: missing value in const declaration
./prog.go:7:22: syntax error: unexpected var at end of statement
./prog.go:9:8: syntax error: unexpected ., expecting type

Explanation:

The above program will generate syntax errors because we cannot create an identifier starting with a digit. Here, 2var is an invalid identifier.


 

Answer Program 5:

Output:

./prog.go:9:2: cannot refer to unexported name fmt.scanf

Explanation:

The above program will generate syntax error, because we used fmt.scanf() instead of fmt.Scanf() to an integer value from the user.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Golang Find Output Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Golang Basics | Find Output Programs | Set 4... >>
<< Golang Basics | Find Output Programs | Set 2...