The "_" symbol in C is used to: 1. Handle function parameters that conflict with keywords; 2. Mark unused variables; 3. Namespace qualification; 4. Macro preprocessor; 5. Anonymous union or enumeration member.
The "_" symbol in C
The "_" symbol in C is also called the underscore, It has the following uses:
1. Function parameters
- When function parameter names conflict with keywords or other identifiers, underscores can be used as replacements .
- For example, if you want to create a function named "int", you can name it "_int".
2. Unused variables
- If the variable does not need to be used, you can add an underscore before the variable name.
- The compiler ignores variables with underscores, helping to avoid compiler warnings.
- For example, create an unused variable "i":
_i = 0;
3. Namespace qualification
- In namespace qualification, the underscore indicates the current namespace.
- Members of other namespaces can be accessed within the current namespace by preceding them with two underscores.
- For example:
using namespace std; cout << _ _ a;
4. Macro preprocessor
- Underscores can be used in macro preprocessors to expand macros or represent macro parameters.
- For example:
#define MACRO(x) _x_
##5. Anonymous union or enumeration
In unions and enumerations, underscores can represent anonymous members. - Anonymous members do not allocate names or memory space.
- For example:
- union { _; int i; };
Note: Although the underscore has a specific purpose in C, But you can still use it to name identifiers. However, it's best to avoid using names that conflict with the compiler's built-in purposes.
The above is the detailed content of What does _ in c++ mean?. For more information, please follow other related articles on the PHP Chinese website!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn