• Post author:
  • Post category:Blog
  • Reading time:2 mins read
  • Post last modified:June 12, 2024

Which of the following identifiers are legal variable names in the C language?

Select three answers.

  • _3monthsOld
  • three_months_old
  • month3
  • 3monthsOld
  • int
  • three months
Explanation & Hints:

In the C programming language, identifiers (including variable names) must follow specific rules:

  1. Identifiers can consist of letters (both uppercase and lowercase), digits, and underscores.
  2. Identifiers must not begin with a digit.
  3. Identifiers must not be keywords of the C language.
  4. Identifiers should not contain spaces or special characters other than the underscore.

Based on these rules, the legal variable names from the options you’ve provided are:

  1. three_months_old – This is a legal identifier as it only contains letters and underscores.
  2. month3 – This is a legal identifier as it starts with a letter and is followed by a digit.
  3. _3monthsOld – While it is somewhat unconventional to start with an underscore followed by a digit, this is technically a legal identifier in C.

The identifiers that are not legal include:

  • 3monthsOld – This is not legal because it starts with a digit.
  • int – This is not legal because “int” is a reserved keyword in C.
  • three months – This is not legal because it contains a space.

Thus, the three legal variable names are _3monthsOld, three_months_old, and month3.

For more Questions and Answers:

Introduction to computer programming, variables, and comments Module 1 Test Answers Full 100%

Notify of
Inline Feedbacks
View all comments