null pointers and void pointers in C + +

Source: Internet
Author: User
Pointer null nullptr The problem of using 0 or NULL to express null pointers in the past:
The null macro for C/s + + is a macro that has many potential bugs. Because some libraries define them as integers 0, some are defined as (void*) 0. The Times in C are fine. But in the era of C + +, this can cause a lot of problems.
C++11 uses the NULLPTR keyword, which is a null pointer that expresses a more accurate, type-safe
#include <iostream>using namespace Std;int main () {//!void voidobject; wrong, cannot declare a variable of type void *pv;//pair, You can declare a pointer of type void int i = 5;PV = &i;//void type pointer to integer variable int *pint = Static_cast<int *> (PV); The void pointer is converted to an int pointer cout << *pint = "<< *pint << endl;return 0;}


null pointers and void pointers in C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.