Computer Science, asked by reshmababu, 1 month ago

The following are invalid identifiers in C++. Write a reason for each.

a) Id#

b) void

c) 2ab

d) avg hgt​

Answers

Answered by anindyaadhikari13
2

\texttt{\textsf{\large{\underline{Answers}:}}}

  • Id# – Invalid because identifier name cannot contain any special characters (except dollars and underscores)

  • void – Invalid because identifier name cannot be a keyword.

  • 2ab – Invalid because identifier name cannot start with a digit.

  • abc hgt – Invalid because identifier name cannot contain spaces.

\texttt{\textsf{\large{\underline{Learn More}:}}}

Naming rules for identifier.

  • Identifier name must not be a keyword.
  • It may contain alphabets, dollars and underscores only. No special characters are allowed.
  • Identifier name must not contain any spaces.
  • Identifier name must not start with a digit.
Answered by zeenamol
1

a) Id# - # (special character) cannot be used

b) void - void is a keywords, which cannot be used

c) 2ab -2 / digit cannot be used as the first character

d) avg hgt - space cannot be used

Similar questions