Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Basics of Variables | Section
Getting Started with Go

bookBasics of Variables

Swipe um das Menü anzuzeigen

Variables represent one of the most crucial concepts in any programming language. They essentially serve as named memory locations that allow us to access and modify the data stored at those memory locations.

With variables, we can store various types of data in memory, including numbers and text. We will delve into data types in the next section. For now, let's focus on declaring and initializing variables without specifying their types.

The var keyword is employed to declare a variable, followed by the variable's name (myVar) and an equal sign (=) to assign the value on the right (10) to the variable. Another example for better understanding is:

index.go

index.go

copy
1
var myVariable = 7

Another way to achieve the same result is by employing the := operator, and in this scenario, there's no need to utilize the var keyword for variable declaration:

index.go

index.go

copy
1
myVariable := 7

Naming Variables

Variables can be given any name, although there are specific rules for declaring variables:

  • A variable's name must start with a letter or an underscore _ character;
  • Variable names are case-sensitive, so myVar and MyVar are distinct variables;
  • A variable cannot have a reserved word as its name. In Go, words like var, for, if, and func, among others, are reserved for special purposes and cannot be used as variable names.

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 3

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Abschnitt 1. Kapitel 3
some-alt