SCRIPTING-AND-PROGRAMMING-FOUNDATIONS practice question 24 of 25

Which type of language requires variables to be declared ahead of time and prohibits their types from changing while the program runs?

Full set: 137 questions
Answer options
A: Scripted (interpreted)
B: Procedural
C: Static Correct answer
D: Compiled
Correct Answer:
C. Static
Explanation

The term "static" refers to static typing, a characteristic of a programming language where type checking is performed at compile-time rather than at runtime. In statically-typed languages like C++, Java, and C#, a variable's type must be explicitly declared before the variable is used. Once declared, the type is fixed and cannot be changed during the program's execution. This approach allows for early error detection and can lead to performance optimizations.

Why Incorrect

Scripted (interpreted): Many scripting languages (e.g., Python, JavaScript) are dynamically typed, which is the opposite of the described behavior. Procedural: This describes a programming paradigm, not a typing system. A language can be procedural and either statically or dynamically typed. Compiled: While most statically-typed languages are compiled, "static" is the more precise term for the type system itself, not the execution model.

References

1. Scott, M. L. (2015). Programming Language Pragmatics (4th ed.). Morgan Kaufmann. (Chapter 6, "Type Systems," Section 6.2, defines and contrasts static and dynamic typing, explicitly stating that static typing involves compile-time checks and fixed variable types).

2. Pierce, B. C. (2002). Types and Programming Languages. MIT Press. (Chapter 1, "Introduction," provides a formal definition of static type systems as a method for proving the absence of certain program behaviors at compile time).

3. Microsoft. (n.d.). C# documentation - Types. Retrieved from https://docs.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/types-and-variables (The documentation for C#, a statically-typed language, states, "C# is a strongly-typed language. Every variable and constant has a type...").

Scroll to Top