In Fortran, which of the following real variable names is invalid according to identifier rules?

Difficulty: Easy

Correct Answer: AB * 2

Explanation:


Introduction:
Classic Fortran identifier rules restrict variable names to specific character sets and formats. This question checks recognition of illegal characters and spacing in identifiers.


Given Data / Assumptions:

  • Options: BETA, ALPHA, A, AB * 2.
  • Context: traditional Fortran naming (letters/digits, starting with a letter).


Concept / Approach:

Fortran variable names must begin with a letter and may contain letters and digits (and underscores in modern Fortran). Spaces and operator symbols (*, +, -, /) are not allowed inside identifiers. Therefore any token containing spaces or arithmetic symbols is invalid as a name.


Step-by-Step Solution:

Step 1: Check each option for illegal characters.Step 2: 'AB * 2' contains a space, an asterisk, and a digit separated by spaces — violates identifier rules.Step 3: 'BETA', 'ALPHA', and 'A' contain only letters and are valid.


Verification / Alternative check:

Attempting to compile with AB * 2 as a variable name will be tokenized as identifier AB, operator *, literal 2 — a syntax error in declarations.


Why Other Options Are Wrong:

'BETA', 'ALPHA', and 'A' adhere to naming rules and compile successfully.


Common Pitfalls:

Confusing expression tokens with identifier characters; assuming spaces can be ignored inside names.


Final Answer:

AB * 2

More Questions from Microprocessors

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion