wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Programming Logic and Design - Chapter 2 - High Quality Programs

Total questions: 35

Worksheet time: 30mins

Name
Class
Date
1.

What is the purpose of initializing a variable in programming?

a)

To give the variable a name.

b)

To reserve memory for the variable.

c)

To assign an initial value to the variable.

d)

To declare the variable's type.

2.

How is a named constant different from a variable?

a)

Variables are used for storing constant values, while named constants can change.

b)

Named constants are declared using the 'var' keyword, while variables use 'const'.

c)

Variables can change their values, while named constants remain constant.

d)

Named constants are only used for mathematical operations.

3.

What is the primary purpose of using meaningful
names for identifiers in programming?

a)

To confuse other programmers.

b)

To save memory.

c)

To make the code more difficult to understand.

d)

To convey the purpose and meaning of the variable or function.

4.

In programming, what is variable declaration?

a)

Assigning a value to a variable.

b)

Reserving memory for a variable.

c)

Naming a variable.

d)

Specifying the type and name of a variable.

5.

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.

a)

Pascal Casing

b)

Hungarian Notation

c)

Camel Casing

d)

String

6.

It describes the unknown value stored in an unassigned variable.

a)

null

b)

garbage

c)

mnemonic

d)

constant

7.

What is modularization in programming?

a)

Using modules or packages as a coding style

b)

Dividing a program into smaller, manageable units or modules

c)

Combining multiple programs into a single executable

d)

Using modular arithmetic for calculations

8.

What is the primary difference between a
numeric variable and a string variable?

a)

Numeric variables store only whole numbers, while string variables store decimal values.

b)

Numeric variables store numerical values, while string variables store sequences of characters.

c)

Numeric variables cannot be used in mathematical operations, while string variables can.

d)

String variables are case-sensitive, while numeric variables are not.

9.

What makes a variable name invalid in programming?

a)

Using reserved keywords as variable names.

b)

Including spaces or special characters other than underscore (_).

c)

Starting the variable name with a number.

d)

All of the choices.

10.

Symbol used for assignment operator?

a)

==

b)

!=

c)

=

d)

<>

11.

It dictates the order in which operations

in the same statement are carried out.

a)

Functionality

b)

order of operations

c)

Rules of precedence

d)

associativity

12.

The act of assigning its first value,

often at the same time the variable is created.

a)

Rules of precedence

b)

Initializing the variable

c)

Encapsulation

d)

Echoing input

13.

Which one of the variables we cannot use as an identifier?

a)

firstName

b)

LastName

c)

DateOfBirth

d)

For

14.

Constants cannot be changed.

a)

True

b)

False

15.

Variable names can include spaces.

a)

True

b)

False

16.

Which of the following variables names is an example of camel case notation?

a)

totalScore

b)

TotalScore

c)

numTotalscore

d)

Total-Score

17.

What is the result of the following expression?

num x = 5 * 9 / 3 + 9;

print x

a)

60

b)

24

c)

4

d)

3.75

18.

What is the result of the following expression?

10 + 5 * 3 - 20

(a)  

19.

What is the result of the following expression?

"one"+"one"

(a)  

20.

Which of the following is an invalid variable?

a)

my_string_1

b)

1st_string

c)

unaNgaNumero

d)

myNumber

21.

Which of the following is an invalid statement?

a)

abc = 100

b)

a b c = 100

c)

a_b_c = 100

d)

a-b-c = 100

22.

What is the primary purpose of choosing

meaningful variable names in programming?

a)

To confuse other programmers

b)

To save memory

c)

To meet language syntax requirements

d)

To make the code more readable and maintainable

23.

Which of the following is a good practice for naming

variables in most programming languages?

a)

Using single-letter variable names

b)

Choosing names that are highly abbreviated

c)

Selecting names that reflect the purpose or content of the variable

d)

Using special characters in variable names

24.

Which of the following variable names is more

descriptive and aligned with good naming conventions?

a)

var1

b)

temperatureInCelsius

c)

x

d)

num

25.

What is the purpose of assigning a value to a variable in programming?

a)

To declare the variable

b)

To perform a comparison

c)

To reserve memory for the variable

d)

To store a specific data value in the variable

26.

In programming, what does the term "string" refer to?

a)

A data type for storing floating-point numbers

b)

A data type for storing characters or sequences of characters

c)

A data type for storing only positive integers

d)

A data type used exclusively for boolean values

27.

What is a named constant in programming?

a)

A variable whose value can be changed during program execution

b)

A variable that is declared without a specific data type

c)

A value that is used in the program but cannot be changed once it is set

d)

A reserved keyword used for control flow statements

28.

What is a "magic number" in programming?

a)

A random value assigned to a variable

b)

A numeric value used in the code without explanation

c)

A constant value that is easy to remember

d)

A special number used for mathematical calculations

29.

What is the potential problem with using magic numbers in code?

a)

Magic numbers improve code readability

b)

Magic numbers make code execution fast

c)

Magic numbers can be hard to understand and maintain

d)

Magic numbers are required for mathematical operations

30.

How is the expression 6−2+4÷2 evaluated

based on the rules of precedence?

a)

4

b)

6

c)

2

d)

8

31.

What is the purpose of a loop in programming?

a)

To create a sequence of random numbers

b)

To execute a set of statements repeatedly based on a condition

c)

To define the data types used in the program

d)

To perform mathematical calculations

32.

If parentheses are used in an expression,

what effect do they have on the rules of precedence?

a)

They have no effect; the rules of precedence are not affected.

b)

Operations inside parentheses are always performed last.

c)

Operations inside parentheses are performed first, overriding the normal rules of precedence.

d)

Parentheses are used only for syntax and do not affect the order of operations.

33.

What is a global variable in programming?

a)

A variable declared inside a function

b)

A variable that can be accessed and modified from any part of the program

c)

A variable with a global scope that can only be used in specific functions

d)

A variable that is assigned a constant value throughout the program

34.

What is the purpose of code commenting as a housekeeping task in programming?

a)

To confuse other programmers

b)

To meet a word count requirement in the code

c)

To explain the purpose of the code and provide documentation

d)

To add decorative elements to the code

35.

What is the purpose of arranging modules in a

hierarchical structure in modular programming?

a)

To confuse other programmers

b)

To ensure equal distribution of workload

c)

To create a visually appealing chart

d)

To represent the organization and relationships between modules