Data items have fixed value are called …….. (MCQ)
a. Identifiers
b. Functions
c. Keywords
d. Literals
The Correct answer and Explanation is:
The correct answer is: d. Literals
Explanation:
In programming, literals refer to fixed values that are directly written in the code. These are constant values that cannot be changed during program execution. They are typically used to represent simple values like numbers, characters, strings, or booleans. The reason they are called literals is because they are “literally” what they represent, and their value is set and immutable.
Types of Literals:
- Numeric literals: These include integers (e.g.,
42) and floating-point numbers (e.g.,3.14). These numbers represent fixed values that can be used in arithmetic operations. - String literals: A sequence of characters enclosed in quotes (either single or double quotes), like
"hello"or'world'. These are fixed text values that do not change unless manually altered in the code. - Character literals: These represent a single character and are typically enclosed in single quotes, such as
'A'. Like other literals, they hold a fixed value throughout the program. - Boolean literals: These are
trueorfalsevalues that are used in logical operations and conditional expressions.
Difference Between Literals and Other Terms:
- Identifiers (option a) are names given to variables, functions, or any other user-defined objects in programming. The value of identifiers can vary based on the state of the program and the logic implemented.
- Functions (option b) are blocks of code designed to perform a specific task. They are not fixed values; instead, they can take different inputs and return various results based on their implementation.
- Keywords (option c) are reserved words in programming languages that have special meaning and cannot be used as identifiers. Examples include
if,for, andwhile.
In contrast, literals are static, constant values used directly in a program. They play a crucial role in defining the data that the program will process.