Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Modifying Variable Values | Getting Started
course content

Course Content

Introduction to GoLang

Modifying Variable ValuesModifying Variable Values

We've learned how to declare a variable. Now, let's understand how to modify the value of a variable.

Take a look at the following program, which prints the value of myVariable using the Println function:

go

index.go

We can use the following syntax for assigning a different value to the variable:

go

index.go

Notice that this time, we omit the var keyword because we are not declaring a new variable. Now, let's add this line to the program:

go

index.go

In the code above, we employed the var keyword to declare a variable. Alternatively, we can use the := operator for variable declaration. In such a case, the code will appear as follows:

go

index.go

Which is the correct way of changing the value of an already declared variable to 10 called myVar:

Select the correct answer

Everything was clear?

Section 1. Chapter 5
course content

Course Content

Introduction to GoLang

Modifying Variable ValuesModifying Variable Values

We've learned how to declare a variable. Now, let's understand how to modify the value of a variable.

Take a look at the following program, which prints the value of myVariable using the Println function:

go

index.go

We can use the following syntax for assigning a different value to the variable:

go

index.go

Notice that this time, we omit the var keyword because we are not declaring a new variable. Now, let's add this line to the program:

go

index.go

In the code above, we employed the var keyword to declare a variable. Alternatively, we can use the := operator for variable declaration. In such a case, the code will appear as follows:

go

index.go

Which is the correct way of changing the value of an already declared variable to 10 called myVar:

Select the correct answer

Everything was clear?

Section 1. Chapter 5
some-alt