Valid variable names

  • Thread starter Deathfish
  • Start date
  • #1
86
0

Main Question or Discussion Point

Hi all, I would like to clarify regarding valid variable names. Well what I fairly understand are the rules regarding names.. What I am unsure about is -- in a test, is there any way to spot a reserved name? For example to make things difficult, trick question, sometimes the question will include

main
print
System
Int

etc. usually in a test we dont have the list of reserved words
 

Answers and Replies

  • #2
33,314
5,006
Hi all, I would like to clarify regarding valid variable names. Well what I fairly understand are the rules regarding names.. What I am unsure about is -- in a test, is there any way to spot a reserved name? For example to make things difficult, trick question, sometimes the question will include

main
print
System
Int

etc. usually in a test we dont have the list of reserved words
You need to be a bit more specific. What language are you asking about? Different languages have different sets of reserved words that can't be used as variable names.
 
  • #3
1,065
53
Regardless of the programming language, if they gave you the list of reserved words and ask you to spot them in the list, that wouldn't be much of test, would it? If you are supposed to be learning a programming language, I presume they expect you to study its reserved words and memorize them; also, to be aware whether the programming language is case-sensitive or not.
 
  • #4
jim mcnamara
Mentor
3,797
2,142
Looks like C to me.

The list of keywords/reserved words in C is short. All of them are lowercase. The C standard (C11)
from what is usually called N1570:
N1570 Committee Draft — April 12, 2011 ISO/IEC 9899:201x:
6.4.1 Keywords
Syntax
1 keyword: one of
auto ∗
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
inline
int
long
register
restrict
return
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while
_Alignas
_Alignof
_Atomic
_Bool
_Complex
_Generic
_Imaginary
_Noreturn
_Static_assert
_Thread_local
 
  • #5
harborsparrow
Gold Member
533
108
One reason programmers like to use an integrated development environment, or IDE, (rather than a simple command window) when writing code, is that the IDE's code window will highlight reserved words in a different color, so it is immediately apparent.

If it isn't possible to get an IDE or syntax-highlighting editor for you language, then you must simply memorize (or keep a list of handy) that language's reserved words. There can be a lot of them, so an IDE is the best solution if you can get it.
 

Related Threads on Valid variable names

  • Last Post
Replies
5
Views
594
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
4
Views
4K
Replies
8
Views
14K
  • Last Post
Replies
5
Views
6K
  • Last Post
2
Replies
25
Views
5K
Replies
8
Views
707
  • Last Post
Replies
4
Views
858
  • Last Post
Replies
4
Views
5K
Top