Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8749853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:45:47+00:00 2026-06-13T12:45:47+00:00

Nowadays, with C++11, Whats recommended to use, Zero or NULL ? The first of

  • 0

Nowadays, with C++11, Whats recommended to use, Zero or NULL? The first of the second if?

int * p = getPointer();

if( 0 == p ){
    // something
}

if( NULL == p ){
    // something
}

UPDATE: I forget the new

if( nullptr == p ){
    // something
}

UPDATE 2: the examples are to show the options to write null pointer, I know is more pleasant to write if( !p ).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:45:48+00:00Added an answer on June 13, 2026 at 12:45 pm

    The other answers are right. But I wanted to say a little more about why nullptr is better.

    In C++11 “perfect forwarding” is very important. It is used everywhere. Obvious places are bind and function. But it is also used in a multitude of other places under the covers. But “perfect forwarding” isn’t perfect. And one of the places it fails is null pointer constants.

    template <class T>
    void display(T)
    {
        std::cout << type_name<T>() << '\n';
    }
    
    template <class T>
    void
    f(T&& t)
    {
        display(std::forward<T>(t));  // "perfectly forward" T
    }
    
    int main()
    {
        f(0);
        f(NULL);
        f(nullptr);
    }
    

    With an appropriate definition of type_name<T>(), on my system this prints out:

    int
    long
    std::nullptr_t
    

    This can easily make the difference between working code and errors. With any luck your errors will come at compile time (with horrible error messages). But you may also get run time errors in some circumstances.

    Aggressively ban use of 0 and NULL in your code.

    Even if you’re not perfect forwarding in your code, code you call (such as the std::lib) is very likely using it under the covers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Learning WPF nowadays. Found something new today with .Net dependency properties. What they bring
I am new to C# (learning it nowadays), and have choosen FB and C#
What is the simplest (to install and use) git client for Windows nowadays?
Nowadays I see in some developers, use function named GetAll or Getlist in each
Nowadays a lot of web applications are providing API for other applications to use.
Nowadays i'm struggling with something i didn't experience maybe 5 years ago, and i
My webservers use the usual Java I/O with thread per connection mechanism. Nowadays, they
Nowadays we see websites with login form/register form in the home page itself (to
Nowadays, I am starting to learn haskell, and while I do it, I try
since memcpy should be highly optimized nowadays, does it still make sense to optimize

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.