Skip to content

Latest commit

 

History

History
118 lines (79 loc) · 2.43 KB

01-static-vs-dynamic-typed-languages.md

File metadata and controls

118 lines (79 loc) · 2.43 KB

Lab: Static vs Dynamic Typed Languages

Take me to the lab!

Help for the VSCode editor.

  1. Which of the following languages are statically typed?
    1. Java
    2. C
    3. C++
    4. Python
    Reveal

    A, B, C

  2. Which of the following languages are dynamically typed?
    1. C++
    2. Python
    3. Javascript
    4. PHP
    Reveal

    B, C, D

  3. Choose the correct statements...
    1. Type checking process occurs at compile time for static typed languages.
    2. Type checking process occurs at runtime for static typed languages.
    3. Type checking process occurs at compile time for runtime typed languages.
    4. Type checking process occurs at runtime for dynamic typed languages.
    Reveal

    A, D

  4. In dynamic typing, a variable is allowed to change its data type...
    • Depends on the data type
    • True
    • False
    • Only if it is an integer
    Reveal

    True

  5. In static typing, a variable is allowed to change its data type...
    • Depends on the data type
    • True
    • False
    • Only if it is an integer
    Reveal

    False

  6. A sample go program is stored under /root/code/simple-project. Inspect it.
    What is the data type assigned to the variable called title?

    You can run this program from the integrated terminal like so

    cd simple-project
    go run main.go
    • float
    • int
    • string
    • Sir
    Reveal

    string

    Examine line 7 of the code.

        title := "Sir"

    Recall that when := is used to create a variable, the type of the new variable is inferred from what follows :=.
    "Sir" is a string constant, therefore the variable title will be of type string.