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

What is _ in c++

下次还敢
Release: 2024-04-26 17:33:13
Original
850 people have browsed it

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 '_':

int _ = 5; // 声明一个匿名整型变量并赋予值 5
Copy after login

2. Ignore parameters

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

void f(int x, int y) {
  int _ = x; // 忽略参数 x
  // ...
}
Copy after login

3. Macro definition

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

#define FUNCNAME __FUNCTION__
Copy after login

4. Some of the reserved keywords

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

#define true _true
Copy after login

5. Escape characters

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

char greeting[] = "Hello, _World!"; // 添加下划线以忽略分号
Copy after login

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!

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template