Any2Quiz
Computer Science / Languages / Golang

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 free

Sample questions

  1. Which keyword is used to declare a variable in Go?

    1. var
    2. let
    3. const
    4. declare
    Show answer

    Answer: A. var

    In Go, the `var` keyword is used to declare variables. For example: `var message string = "Hello, World!"`

  2. Which Go construct is used for conditional execution based on a boolean expression?

    1. if statement
    2. switch statement
    3. for loop
    4. 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.

  3. What is the keyword used to import packages in Go?

    1. import
    2. include
    3. require
    4. use
    Show answer

    Answer: A. import

    The `import` keyword is used to bring code from other packages into your current package.

  4. What is the Go keyword for creating a new channel?

    1. make
    2. new
    3. channel
    4. create
    Show answer

    Answer: A. make

    Channels are created using the built-in `make` function. Example: `myChannel := make(chan int)`.

  5. What is the purpose of the `defer` keyword in Go?

    1. To schedule a function call to run just before the enclosing function returns
    2. To define a function that runs immediately
    3. To create a loop
    4. 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.

Take the full quiz

More quizzes

Browse all Golang quizzes