15.6k views
1 vote
Which of the following is not a valid variable name? 2 myInt 2. return 3. myInteger 4. total3

1 Answer

3 votes

Answer:

Correct answer is option (2) that is "return".

Step-by-step explanation:

In any programming language, a variable name can be made up of letters (lower and upper case) and digits. we can also use "_" underscore character for declaring the variables but we cannot use any special character like “$”.We cannot use digits in the beginning of variables name. And we also cannot use reserved keywords of the language like "new","return","while" etc. There should not be space between the variable names. Options 1, 3 and 4 are not violating any of these properties. But in option (2), "return" is a reserved keyword. That is why it is not a valid variable name.

Some example of valid variables name:

foo

BAZ

Bar

_foo42

foo_bar

Some example of invalid variables name:

$foo ($ not allowed)

while ( keywords )

2foo (started with digit)

my foo (spaces )

User Amir Imam
by
5.4k points