There are five kinds of bracket characters in C: parentheses are used for function calls, conditional statements and control flow structures; square brackets are used for array/vector indexing and type conversion; curly brackets are used for code blocks; angle brackets are used for For template declarations and function overloading; parentheses are used to capture the variable list of a lambda expression.
Brackets in C
There are five bracket characters in the C programming language:
()
): used for function calls, conditional statements and control flow structures. []
): used for indexing and type conversion of arrays and vectors. {}
): used for code blocks (such as function bodies, loop bodies, and conditional statement bodies). <>
): used for template declarations and function overloading. ()
): Used to capture the variable list of the lambda expression. Parentheses
myFunction(arg1, arg2);
if (condition) { ... }
while (condition) { ... }
, for (initializer; condition ; increment) { ... }
square brackets
array[index];
vector[index];
static_cast<type>(expression);
Braces
Function body:
<code class="cpp">void myFunction() { // 代码块 }</code>
Loop body:
<code class="cpp">while (condition) { // 代码块 }</code>
Conditional statement body:
<code class="cpp">if (condition) { // 代码块 }</code>
Angle brackets
template<typename T> class MyTemplate { ... };
int myFunction(int arg);
double myFunction(double arg);
Parents
Capture the variable list of the lambda expression:
<code class="cpp">auto myLambda = [](int& number) { // 访问捕获的变量 number };</code>
The above is the detailed content of How to type square brackets in c++. For more information, please follow other related articles on the PHP Chinese website!