Syntax Quiz - Languages Golang
Free practice quiz: Syntax (Languages Golang). 49 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
Play all 49 questions freeSample questions
Which keyword is used to declare a variable in Go?
- var
- let
- const
- declare
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?
- if statement
- switch statement
- for loop
- while loop
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?
- import
- include
- require
- use
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?
- make
- new
- channel
- create
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?
- To schedule a function call to run just before the enclosing function returns
- To define a function that runs immediately
- To create a loop
- To declare a variable
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.