Valid Variable Names: Rules & Tests

  • Thread starter Thread starter Deathfish
  • Start date Start date
  • Tags Tags
    Variable
Click For Summary
The discussion centers on the challenge of identifying reserved variable names in programming languages during tests. It highlights that different programming languages have unique sets of reserved words, and understanding these is crucial for coding. The conversation emphasizes the importance of memorizing these keywords, particularly in languages like C, which has a concise list of lowercase reserved words. It notes that integrated development environments (IDEs) can aid in this process by highlighting reserved words, making it easier for programmers to spot them. If an IDE is unavailable, maintaining a list or memorizing the reserved words is recommended for effective coding.
Deathfish
Messages
80
Reaction score
0
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 don't have the list of reserved words
 
Technology news on Phys.org
Deathfish said:
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 don't 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.
 
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.
 
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
 
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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 89 ·
3
Replies
89
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 75 ·
3
Replies
75
Views
6K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
16
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K