Which of the following is not a valid variable name in most programming…
2023
Which of the following is not a valid variable name in most programming languages?
- A.
myVariable
- B.
123Variable
- C.
_myVariable
- D.
More than one of the above
- E.
None of the above
Attempted by 1841 students.
Show answer & explanation
Correct answer: B
In most programming languages, variable names must follow specific rules:
Must start with a letter (a-z, A-Z) or underscore (_).
Can include letters, digits (0-9), and underscores.
Cannot start with a digit.
Cannot contain special characters or spaces.
Now, evaluate each option:
Option A: 'myVariable' starts with a letter and uses valid characters. This is valid.
Option B: '123Variable' starts with digits. This is invalid.
Option C: '_myVariable' starts with an underscore and uses valid characters. This is valid.
Option D: 'More than one of the above' is incorrect because only one option is invalid.
Option E: 'None of the above' is incorrect because one option is invalid.
Therefore, the option that is not a valid variable name is '123Variable'.
हिन्दी उत्तर:
अधिकांश प्रोग्रामिंग भाषाओं में वेरिएबल नाम निम्न नियमों का पालन करना चाहिए:
एक अक्षर (a-z, A-Z) या अंडरस्कोर (_) से शुरू होना चाहिए।
अक्षर, अंक (0-9) और अंडरस्कोर शामिल कर सकते हैं।
अंक से शुरू नहीं हो सकता।
विशेष वर्ण या स्पेस नहीं हो सकते।
अब प्रत्येक विकल्प का विश्लेषण करें:
विकल्प A: 'myVariable' एक अक्षर से शुरू होता है और वैध वर्णों का उपयोग करता है। यह वैध है।
विकल्प B: '123Variable' अंकों से शुरू होता है। यह अवैध है।
विकल्प C: '_myVariable' अंडरस्कोर से शुरू होता है और वैध वर्णों का उपयोग करता है। यह वैध है।
विकल्प D: 'उपर्युक्त में से एक से अधिक' गलत है क्योंकि केवल एक विकल्प अवैध है।
विकल्प E: 'उपर्युक्त में से कोई नहीं' गलत है क्योंकि एक विकल्प अवैध है।
इसलिए, जो वेरिएबल नाम अवैध है वह '123Variable' है।