Font size
WorksheetsProgramming Logic and Design - Chapter 2 - High Quality Programs
Total questions: 35
Worksheet time: 30mins
What is the purpose of initializing a variable in programming?
To give the variable a name.
To reserve memory for the variable.
To assign an initial value to the variable.
To declare the variable's type.
How is a named constant different from a variable?
Variables are used for storing constant values, while named constants can change.
Named constants are declared using the 'var' keyword, while variables use 'const'.
Variables can change their values, while named constants remain constant.
Named constants are only used for mathematical operations.
What is the primary purpose of using meaningful
names for identifiers in programming?
To confuse other programmers.
To save memory.
To make the code more difficult to understand.
To convey the purpose and meaning of the variable or function.
In programming, what is variable declaration?
Assigning a value to a variable.
Reserving memory for a variable.
Naming a variable.
Specifying the type and name of a variable.
The format for naming variables in which the initial letter is lowercase,
multiple-word variable names are run together, and each new word
within the variable name begins with an uppercase letter.
Pascal Casing
Hungarian Notation
Camel Casing
String
It describes the unknown value stored in an unassigned variable.
null
garbage
mnemonic
constant
What is modularization in programming?
Using modules or packages as a coding style
Dividing a program into smaller, manageable units or modules
Combining multiple programs into a single executable
Using modular arithmetic for calculations
What is the primary difference between a
numeric variable and a string variable?
Numeric variables store only whole numbers, while string variables store decimal values.
Numeric variables store numerical values, while string variables store sequences of characters.
Numeric variables cannot be used in mathematical operations, while string variables can.
String variables are case-sensitive, while numeric variables are not.
What makes a variable name invalid in programming?
Using reserved keywords as variable names.
Including spaces or special characters other than underscore (_).
Starting the variable name with a number.
All of the choices.
Symbol used for assignment operator?
==
!=
=
<>
It dictates the order in which operations
in the same statement are carried out.
Functionality
order of operations
Rules of precedence
associativity
The act of assigning its first value,
often at the same time the variable is created.
Rules of precedence
Initializing the variable
Encapsulation
Echoing input
Which one of the variables we cannot use as an identifier?
firstName
LastName
DateOfBirth
For
Constants cannot be changed.
True
False
Variable names can include spaces.
True
False
Which of the following variables names is an example of camel case notation?
totalScore
TotalScore
numTotalscore
Total-Score
What is the result of the following expression?
num x = 5 * 9 / 3 + 9;
print x
60
24
4
3.75
What is the result of the following expression?
10 + 5 * 3 - 20
(a)
What is the result of the following expression?
"one"+"one"
(a)
Which of the following is an invalid variable?
my_string_1
1st_string
unaNgaNumero
myNumber
Which of the following is an invalid statement?
abc = 100
a b c = 100
a_b_c = 100
a-b-c = 100
What is the primary purpose of choosing
meaningful variable names in programming?
To confuse other programmers
To save memory
To meet language syntax requirements
To make the code more readable and maintainable
Which of the following is a good practice for naming
variables in most programming languages?
Using single-letter variable names
Choosing names that are highly abbreviated
Selecting names that reflect the purpose or content of the variable
Using special characters in variable names
Which of the following variable names is more
descriptive and aligned with good naming conventions?
var1
temperatureInCelsius
x
num
What is the purpose of assigning a value to a variable in programming?
To declare the variable
To perform a comparison
To reserve memory for the variable
To store a specific data value in the variable
In programming, what does the term "string" refer to?
A data type for storing floating-point numbers
A data type for storing characters or sequences of characters
A data type for storing only positive integers
A data type used exclusively for boolean values
What is a named constant in programming?
A variable whose value can be changed during program execution
A variable that is declared without a specific data type
A value that is used in the program but cannot be changed once it is set
A reserved keyword used for control flow statements
What is a "magic number" in programming?
A random value assigned to a variable
A numeric value used in the code without explanation
A constant value that is easy to remember
A special number used for mathematical calculations
What is the potential problem with using magic numbers in code?
Magic numbers improve code readability
Magic numbers make code execution fast
Magic numbers can be hard to understand and maintain
Magic numbers are required for mathematical operations
How is the expression 6−2+4÷2 evaluated
based on the rules of precedence?
4
6
2
8
What is the purpose of a loop in programming?
To create a sequence of random numbers
To execute a set of statements repeatedly based on a condition
To define the data types used in the program
To perform mathematical calculations
If parentheses are used in an expression,
what effect do they have on the rules of precedence?
They have no effect; the rules of precedence are not affected.
Operations inside parentheses are always performed last.
Operations inside parentheses are performed first, overriding the normal rules of precedence.
Parentheses are used only for syntax and do not affect the order of operations.
What is a global variable in programming?
A variable declared inside a function
A variable that can be accessed and modified from any part of the program
A variable with a global scope that can only be used in specific functions
A variable that is assigned a constant value throughout the program
What is the purpose of code commenting as a housekeeping task in programming?
To confuse other programmers
To meet a word count requirement in the code
To explain the purpose of the code and provide documentation
To add decorative elements to the code
What is the purpose of arranging modules in a
hierarchical structure in modular programming?
To confuse other programmers
To ensure equal distribution of workload
To create a visually appealing chart
To represent the organization and relationships between modules
