Syntax Quiz - Languages Golang
Free practice quiz: Syntax (Languages Golang). 49 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
This Languages Golang practice quiz has 49 multiple-choice questions on Syntax, and 49 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.
Start quiz: 49 questions, freeSample questions
Which keyword is used to declare a variable in Go?
Show answer
Answer: A. var
In Go, the `var` keyword is used to declare variables. For example: `var message string = "Hello, World!"`
Which Go construct is used for conditional execution based on a boolean expression?
Show answer
Answer: A. if statement
The `if` statement is used for conditional execution in Go. It evaluates a boolean expression and executes a block of code if the expression is true.
What is the keyword used to import packages in Go?
Show answer
Answer: A. import
The `import` keyword is used to bring code from other packages into your current package.
What is the Go keyword for creating a new channel?
Show answer
Answer: A. make
Channels are created using the built-in `make` function. Example: `myChannel := make(chan int)`.
What is the purpose of the `defer` keyword in Go?
Show answer
Answer: A. To schedule a function call to run just before the enclosing function returns
The `defer` statement defers the execution of a function call until the function returns. Deferred calls are executed in LIFO (Last-In, First-Out) order.
More questions in this quiz
Answers and explanations are in the full quiz.
- What is the correct syntax for a single-line comment in Go?
- What is the keyword used to define a function in Go?
- Which operator is used for addition in Go?
- What is the zero value for an integer type in Go?
- What is the Go keyword for defining a constant?
- What is the correct syntax for a multi-line comment in Go?
- Which keyword is used to return a value from a function in Go?
- What is the zero value for a boolean type in Go?
- What is the Go keyword for loop that iterates over a range (like elements of a slice or array)?
- Which keyword is used to define a structure in Go?
- What does the `:=` operator do in Go?
- What is the Go keyword for creating a new goroutine?
- Which of the following is a valid Go identifier?
- What is the zero value for a string type in Go?
- Which keyword is used to switch between different cases in Go?
- What is the Go keyword for defining a package?
- Which operator is used for assignment in Go?
- What is the zero value for a pointer type in Go?
- Which loop structure in Go executes indefinitely until a condition is met or a `break` statement is encountered?
- What is the Go keyword used to create a new map?
- Which keyword is used to define a type alias in Go?
- What is the Go keyword used to iterate over a string, yielding runes?
- Which operator is used for division in Go?
- What is the Go keyword for implementing an interface?
- What is the zero value for a slice type in Go?
- Which Go statement is used to skip the rest of the current iteration of a loop and continue to the next iteration?
- What is the correct syntax for accessing a field of a Go struct?
- Which type of statement allows executing different code blocks based on the value of an expression?
- What is the zero value for a map type in Go?
- Which keyword is used to terminate a loop or a `switch` statement immediately in Go?
- What is the Go keyword for defining an interface?
- Which operator is used for modulo (remainder) in Go?
- What is the Go keyword used to send a value on a channel?
- What is the correct syntax for receiving a value from a channel in Go?
- Which keyword is used to define an enumerated type (though Go doesn't have explicit enums, this is the closest concept)?
- Which Go keyword is used for type assertion?
- What is the Go keyword used to ensure that a specific block of code executes regardless of whether an error occurs or not, often used with `defer`?
- Which of the following correctly defines a two-dimensional array of integers in Go?
- What is the purpose of the `iota` identifier in Go?
- Which Go keyword is used to explicitly signal an error or a panic condition?
- What is the correct syntax to declare a function that returns multiple values in Go?
- Which of the following is NOT a valid way to declare a string variable in Go?
- What is the Go keyword for creating a function that can be called concurrently as a separate thread of execution?
- Which operator is used for bitwise XOR in Go?