Which of these are not legal identifiers. Select all the correct answers.

  1. 1alpha

  2. _abcd

  3. xy+abc

  4. transient

  5. account-num

  6. very_long_name


Correct Option: A,C,D,E

AI Explanation

To answer this question, we need to understand the rules for legal identifiers in programming languages.

In general, legal identifiers must follow these rules:

  1. They can only contain letters (both uppercase and lowercase), digits, and underscores.
  2. They cannot start with a digit.
  3. They cannot contain special characters such as +, -, *, /, etc.

Let's go through each option to determine which ones are not legal identifiers:

A. 1alpha - This option is not a legal identifier because it starts with a digit.

B. _abcd - This option is a legal identifier because it starts with an underscore and contains only letters, digits, and underscores.

C. xy+abc - This option is not a legal identifier because it contains the special character '+'.

D. transient - This option is a legal identifier because it contains only letters.

E. account-num - This option is not a legal identifier because it contains the hyphen '-'.

F. very_long_name - This option is a legal identifier because it contains only letters, and underscores.

Therefore, the correct answers are A, C, D, and E.

Find more quizzes: