Which of the following identifiers are C++ reserved words, standard, other valid , or invalid identifiers?

Okay this is a question from my homework, and I'm a bit confused, especially with Standard identifiers and Other valid identifiers. I mean what's the difference ?. Anyway, Here are my answers so far:

void - Reserved word
MAX-ENTRIES - valid Identifier
double - Reserved Word
time - valid Identifier
G - valid Identifier
Sue's - Invalid identifier
return - Reserved word
cout - Standard Identifier
xyz123 - Valid Identifier
part#2 - Invalid Identifier
"char" - Invalid Identifier
#include - Invalid Identifier ?????????????
This_is_a_long-one - Valid Identifier
_xyz - Invalid Identifier
9xyz - Invalid Identifier
main - Reserved word
mutable - Reserved word
double - Reserved word
max?out - invalid identifier



Am I correct ? Correct me if I'm wrong, please :).
so you should classify these "words" in which categories:
Standard identifier, valid , invalid identifier and reserved word?

Also _xyz is a valid identifier.

I am not sure I follow your classification. For example "char" is invalid identifier but it's string literal. You came up with the categories?
That's how the question is. I just edited off a bit so It could fit in the title. Here's the full thing:

Question 1: Which of the following identifiers is (a) C++ reserved words, (b) standard identifiers, (c) other valid identifiers, and (e) invalid identifiers?

And if it matters, we are operating on Visual Studio 2008.
Last edited on
MAX-ENTRIES - valid Identifier


Depending on the actual context, this would be interpreted as the identifier MAX minus (subtract) the identifier ENTRIES. You cannot use a hyphen in an identifier.
Also, time is a function in the standard library. main is not a reserved word. #include can be considered one.
This_is_a_long-oneThis is not a valid identifier. (They are two valid identifiers separated by a 'minus' symbol.)

#include is (d) none of the above. It is a pre-processor directive, but given the options, you are correct.

BTW, I don't like the term "invalid identifier" applied here. Either it is an identifier or it is not. An identifier is only invalid when it cannot be used where it is found.
Athar, I think at the point we are in right now, its not MAX(minus)ENTRIES. Its just a dash.

Alright so I just looked at the slides and our instructor's definition of Standard identifiers are those reserved for using namespace std;

So this is pretty much my new solution. Anything wrong going on ?


void - Reserved word
MAX-ENTRIES - valid Identifier
double - Reserved Word
time - valid Identifier
G - valid Identifier
Sue's - Invalid identifier
return - Reserved word
cout - Standard Identifier
xyz123 - Valid Identifier
part#2 - Invalid Identifier
"char" - Invalid Identifier
#include - Invalid Identifier
This_is_a_long-one - Valid Identifier
_xyz - Valid Identifier
9xyz - Invalid Identifier
main - Standard Identifier
mutable - C++ Reserved word
double - C++ Reserved word
max?out - invalid identifier

I think that #include is an invalid identifier as he included the #. If it was just include, it would've been a reserved word.

I tried using time as an identifier doing int time=4; then cout<<time; and it showed 4 as an output. I assume it should be considered as a valid identifier ?
Last edited on
dash can't be part of an identifier.
You can use letters (either upper or lowercase*), digits (but can't start with one) or underscore.

Dunno what do you mean with standard identifier.

*keep in mind that c++ is case sensitive
I tried using time as an identifier doing int time=4; then cout<<time; and it showed 4 as an output. I assume it should be considered as a valid identifier ?

It is a valid identifier. Just like cout is. If you consider cout a "standard identifier", then time is too.

I think that #include is an invalid identifier as he included the #. If it was just include, it would've been a reserved word.

include is not a keyword. However, #include is a preprocessor directive.
Last edited on
Topic archived. No new replies allowed.