搜尋此網誌

2025年4月13日星期日

Qualifiers in C++

snippet: a small piece of information

const int

In C++, the void keyword is used to indicate the absence of a type.

In C++, using const with function parameters ensures that the parameter cannot be modified within the function.

In C++, the volatile keyword is a type qualifier that tells the compiler that a variable's value can be changed at any time, even outside the program's control.

In C++, the mutable qualifier is a special keyword that allows modification of a class member variable, even if the containing object is declared as const.

In C++, the inline qualifier is used to suggest to the compiler that the function's code should be expanded at the point of each call, rather than performing a traditional function call. This can improve performance by avoiding the overhead of a function call, especially for small, frequently used functions.

The constexpr qualifier in C++ is used to indicate that a variable, function, or object can be evaluated at compile time, enabling optimizations and ensuring constant expressions.

In C++, compile time refers to the phase during which the source code is translated into machine code by the compiler. During this phase, certain operations and checks are performed, such as syntax validation, type checking, and optimization.

A variable declared as static inside a function is initialized only once and retains its value between function calls. Although its scope is limited to the function, its lifetime extends across the entire execution of the program.

encapsulate: to express the most important parts of something in a few words, a small space or a single object

Within a class definition, a data member declared with static is shared among all instances of the class—the class itself holds one instance of the variable instead of each object having its own copy.

In C++, the scope resolution operator (::) is used to access members or entities that are defined in a specific scope, such as a namespace, class, or global scope. 

Microsoft Copilot

沒有留言:

發佈留言