Introduction to Arrays
Part of the Fundamentals section of Coddy's GO journey — lesson 67 of 109.
Arrays in Go store fixed-size collections of elements of the same type.
Declare an array of 5 integers:
var scores [5]intInitialize an array with values:
var fruits = [3]string{"apple", "banana", "orange"}Access array elements using index (starting from 0):
fmt.Println(fruits[1])This displays:
bananaModify an array element:
fruits[0] = "mango"
fmt.Println(fruits)Result:
[mango banana orange]Cheat sheet
Arrays in Go store fixed-size collections of elements of the same type.
Declare an array:
var scores [5]intInitialize with values:
var fruits = [3]string{"apple", "banana", "orange"}Access elements using index (starting from 0):
fmt.Println(fruits[1]) // bananaModify elements:
fruits[0] = "mango"Try it yourself
This lesson doesn't include a code challenge.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Comparison & Logical Operators
Comparison Operators - Part 1Comparison Operators - Part 2Logical AND OperatorLogical OR OperatorLogical NOT OperatorOperator Precedence BasicsRecap - Making Comparisons7Control Flow: Loops
What The `for` Loop ExplainedFor Loop - BasicFor Loop - Condition OnlyThe `break` KeywordThe `continue` KeywordNested LoopsRecap - Repeating Actions10Composite Types: Arrays
Introduction to ArraysDeclaring ArraysInitializing ArraysAccessing Array ElementsArray Length with `len`Iterating Over ArraysMulti-dimensional Arrays2Variables and Basic Data Types
What is a variableType Inference with `:=`Integers (int)Floating-Point NumbersBooleansStringsZero ValuesConstantsNaming ConventionsRecap - Variables and Types5Basic Input/Output
Formatted OutputFormat VerbsPrinting TypesGetting Basic User InputRecap - Input and Output8Functions
Understanding FunctionsDeclaring a FunctionCalling FunctionsFunction ParametersReturning a Single ValueReturning Multiple ValuesNamed Return ValuesFunction Scope BasicsRecap - Creating Reusable Code3Basic Operators
Arithmetic OperatorsDivision OperatorThe Modulo OperatorAssignment OperatorAugmented Assignment OperatorsIncrement and DecrementRecap - Calculations6Control Flow: Conditionals
The `if` StatementThe `else` KeywordThe `else if` KeywordVariable Shadowing in `if`Initializing VariablesThe `switch` StatementSwitch with ExpressionsSwitch without ExpressionThe `fallthrough` KeywordRecap - Making Decisions