In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "can the null pointer of C++ use nullptr instead of NULL?". In daily operation, I believe that many people have doubts about whether the null pointer of C++ can use nullptr instead of NULL. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question that "can the null pointer of C++ use nullptr instead of NULL?" Next, please follow the editor to study!
First of all, let's learn what a null pointer is. A null pointer is void*.
In order to avoid the appearance of a wild pointer (that is, the pointer does not point to any address), it is best to initialize a pointer as soon as it is declared.
If it is not clear which variable the pointer points to for the time being, you can give NULL, such as:
Int* p = NULL
In addition to NULL, the new standard called nullptr has been introduced to represent a null pointer.
Nullptr is neither an integer type nor a pointer type. The type of nullptr is std::nullptr_t, which can be converted to any pointer type.
Why is nullptr recommended instead of NULL?
This is because in C++, NULL is a constant defined as 0, and there is a problem when a function is overloaded.
For example, when there are two functions:
Void foo (int n)
Void foo (char* s)
Function overloading: C++ allows multiple similar functions of the same name to be declared in the same scope, and the formal parameter lists (number of parameters, type, order) of these functions must be different.
# include using namespace std;void foo (int n) {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.