Skip to content

Latest commit

 

History

History
121 lines (84 loc) · 2.07 KB

05-constants.md

File metadata and controls

121 lines (84 loc) · 2.07 KB

Lab: Constants

Take me to the lab!

Help for the VSCode editor.

  1. A constant is initialised using the keyword:
    • var
    • fixed_var
    • const
    • constant
    Reveal

    const

  2. Select the valid statements for declaring and initialising a constant
    1. const c int = "mouse"
    2. const c int = 90
    3. const c = 90
    4. const c int = 90.00
    Reveal

    B, C

    A and D are type mismatches.

  3. Select the correct statements
    1. const c int = 70
    2. const c int
      c = 70
    3. var c int
      c = 70
    4. var c = 90
    Reveal

    A, C, D

    B is incorrect becaose a const must be assigned a value when it is declared, not in a separate statement.

  4. Can you use shorthand declaration for declaring constants (:=)
    • No
    • Yes
    • Optional
    • None of the above
    Reveal

    No

  5. Which of the following statement will throw an error
    1. const name = "Harry"
      fmt.Print(name)
    2. var name = "Harry"
      fmt.Print(name)
    3. const name = "Harry"
      name = "Snape"
      fmt.Print(name)
    4. var name string = "Harry"
      fmt.Print(name)
    Reveal

    C

    const is by definition constant. This means that once declared, it cannot be reassigned.