Computer Science, asked by lakshay443642, 2 months ago

Which of the following are valid identifiers and why/why not:
(i) Myfile (ii) 29CLCT (iii) DATE9_7_77
(iv) break (v) $1_to_$10

Answers

Answered by IIAstuteIshII
4

ɧɛƖƖơ ɱąɬɛ

Qᴜᴇsᴛɪᴏɴ:

ᴡʜᴀᴛ ᴀʀᴇ ᴛʜᴇ ʀᴜʟᴇs Fᴏʀ ᴀɴ ɪᴅᴇɴᴛɪFɪᴇʀ ᴛᴏ ʙᴇ ᴠᴀʟɪᴅ ??

ᴀɴsᴡᴇʀ:

  • ᴛʜᴇ Fɪʀsᴛ ᴄʜᴀʀᴀᴄᴛᴇʀ ᴍᴜsᴛ ʙᴇ ᴀ ʟᴇᴛᴛᴇʀ (ᴇɪᴛʜᴇʀ ᴀ-ʙ ᴏʀ ᴀ-ʙ).
  • ɪᴛ ᴄᴀɴ ᴀʟsᴏ sᴛᴀʀᴛ ᴡɪᴛʜ ᴜɴᴅᴇʀsᴄᴏʀᴇ(  _  ) .
  • ᴅɪɢɪᴛs ᴄᴀɴ ʙᴇ ᴀ ᴘᴀʀᴛ ᴏF ᴀ ᴠᴀʟɪᴅ ɪᴅᴇɴᴛɪFɪᴇʀ ʙᴜᴛ ᴀɴ ɪᴅᴇɴᴛɪFɪᴇʀ sʜᴏᴜʟᴅ ɴᴏᴛ sᴛᴀʀᴛ ᴡɪᴛʜ ᴀ ᴅɪɢɪᴛ.
  • ᴀ ᴠᴀʟɪᴅ ɪᴅᴇɴᴛɪFɪᴇʀ ᴅᴏᴇs ɴᴏᴛ ʜᴀᴠᴇ ᴀɴʏ sᴘᴇᴄɪᴀʟ ᴄʜᴀʀᴀᴄᴛᴇʀ ᴏᴛʜᴇʀ ᴛʜᴀɴ ᴜɴᴅᴇʀsᴄᴏʀᴇ (  _  ).
  • ᴀɴʏ ᴠᴀʟɪᴅ ɪᴅᴇɴᴛɪFɪᴇʀ ᴍᴜsᴛ ɴɪᴛ ʙᴇ ᴀ ᴋᴇʏᴡᴏʀᴅ ᴏF ᴘʏᴛʜᴏɴ.

Qᴜᴇsᴛɪᴏɴ:

ᴡʜɪᴄʜ ᴏF ᴛʜᴇ Fᴏʟʟᴏᴡɪɴɢ ᴀʀᴇ ᴠᴀʟɪᴅ ɪᴅᴇɴᴛɪFɪᴇʀs ᴀɴᴅ ᴡʜʏ/ᴡʜʏ ɴᴏᴛ:

ᴀɴsᴡᴇʀ:

(i) Myfile →  valid  

ʀᴇᴀsᴏɴ :

(follows all the rules mentioned above)

_______________________

(ii) 29CLCT → invalid

ʀᴇᴀsᴏɴ :

(starts with a digit )

_______________________

(iii) DATE9_7_77 →  valid  

ʀᴇᴀsᴏɴ :

(follows all the rules mentioned above)

_______________________

(iv) break →  invalid  

ʀᴇᴀsᴏɴ :

(python keyword)

_______________________

(v) $1_to_$10  →  invalid  

ʀᴇᴀsᴏɴ :

(have a special character ($))

_______________________

ɧơ℘ɛ ıɬ ɧɛƖ℘ʂ ყơų  ☺

Answered by harshvirsing55
0

Answer:-

\red{\fbox{\tt Valid Identifiers}}

(i)  Myfile

(ii) DATE9_7_77

\blue{\fbox{\tt Invalid Identifiers}}

(i) 29CLCT

must not begin with a digit.

(ii) break

A keyword cannot be used as an identifier.

(iii) $1_to_$10

Only special character allowed is undercore ; $ not allowed.

\orange{\tt Hope it will} \green{\tt help you.} ✨​

Similar questions