Home >Backend Development >C++ >What is _ in c++

What is _ in c++

下次还敢
下次还敢Original
2024-04-26 17:33:13831browse

In C, the underscore ('_') is used for: 1. Anonymous variables; 2. Ignore parameters; 3. Macro definition (indicating the current function name); 4. Reserved keywords (override C keywords ); 5. Escape characters (semicolons are ignored); 6. Reserved identifiers (used by the standard library and user libraries).

What is _ in c++

_ in C In the C programming language, the underscore ('_') has several uses :

1. Anonymous variable

When declaring a variable, if you do not specify a variable name, you can name it '_':

<code class="cpp">int _ = 5; // 声明一个匿名整型变量并赋予值 5</code>

2. Ignore parameters

In the function parameter list, you can use '_' to ignore unnecessary parameters:

<code class="cpp">void f(int x, int y) {
  int _ = x; // 忽略参数 x
  // ...
}</code>

3. Macro definition

In the preprocessor, the underscore is used to indicate the current function name:

<code class="cpp">#define FUNCNAME __FUNCTION__</code>

4. Some of the reserved keywords

C Keywords may be overridden by user-defined names, in which case '_' can be used instead:

<code class="cpp">#define true _true</code>

5. Escape characters

in string literals , the underscore can be used as an escape character:

<code class="cpp">char greeting[] = "Hello, _World!"; // 添加下划线以忽略分号</code>

6. Reserved identifiers

The standard library and user-defined libraries may use identifiers starting with an underscore. These identifiers are considered reserved and are not recommended for use by users.

The above is the detailed content of What is _ in c++. 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
Previous article:What is | in c++Next article:What is | in c++