08 Feb C++ Tokens
C++ Tokens are the individual words and punctuation, which is the smallest element of a program, understandable by the compiler. In easier language, C++ tokens are individual units in a program.
In this lesson, we will learn about the following Tokens in C++:
- Identifiers
- Keywords
- Whitespace
C++ Identifiers
Identifiers in C++ are used for naming variables, functions, and arrays. Do not use keywords as identifiers. You cannot use keywords as identifiers; they are reserved for special use.
Here are some examples of valid identifiers:
1 2 3 4 5 6 |
marks _marks a emp2 |
Rules for naming Identifiers in C++
To name C++ Identifiers, follow these rules:
- The identifier must begin with a letter or underscore (_).
- C++ identifiers must consist of only letters, digits, or underscores.
- Do not add any special characters to the identifiers.
- It should not be a keyword.
- It should not contain any white space.
C++ Keywords
Keywords are reserved words used in programming languages. The compiler already knows these names, so you cannot use them as variable names,
Over 30 keywords are part of C++ and are known to the compiler.
Here is a list:
C++ Whitespace
White space in C++ includes vertical tabs, horizontal tabs, blank, comments, end-of-line, etc. A line with whitespace isn’t considered by the compiler.
You can add a comment there, as shown below:
1 2 3 4 |
// displaying a value cout << "Value = " << a << endl; |
Use whitespace to separate parts of statements; for example:
1 2 3 |
float points; |
If you liked the tutorial, spread the word and share the link and our website Studyopedia with others:
For Videos, Join Our YouTube Channel: Join Now
Read More:
No Comments