1.1.1 Variables and constants

Cards (17)

  • What are the two key components of a variable?
    Identifier and data type
  • In Python, the statement x = 5 declares a variable with the value 5.
  • What is the purpose of a data type in a variable declaration?
    Determines the type of value
  • Initializing a variable means assigning an initial value when it is declared.
  • What are the three types of variable scope?
    Global, local, block
  • A global variable is accessible throughout the entire program.
  • Where is a local variable accessible?
    Within a function
  • Why is it important to initialize variables?
    Ensures data integrity
  • Variable naming conventions are optional rules to improve code readability.
  • What is the recommended case for variable names in most programming languages?
    Lowercase
  • The underscore in total_price is an example of snake_case naming.
  • Variable naming conventions are rules and best practices to ensure readability and maintainability.
  • Constants are variables whose values can be changed during program execution.
    False
  • In C++, constants are declared using the keyword const.
  • Match the programming language with its constant declaration syntax:
    Python ↔️ CONST_NAME = value
    C++ ↔️ const data_type CONST_NAME = value;
  • In Python, no explicit type declaration is needed for variables, whereas C++ requires it.
  • Arrange the types of variable scope from broadest to narrowest:
    1️⃣ Global
    2️⃣ Local
    3️⃣ Block