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

  • SEARCH
  • Home
  • 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 8570311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:31:46+00:00 2026-06-11T18:31:46+00:00

I remember reading somewhere that it’s neccessary for delete NULL to be a valid

  • 0

I remember reading somewhere that it’s neccessary for delete NULL to be a valid operation in C++, but I can’t remeber the reason why it should be so. Would someone please remind me?

  • 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-11T18:31:47+00:00Added an answer on June 11, 2026 at 6:31 pm

    The rule is not strictly necessary in that the language could exist without it; it is simply a decision made by the standards committee. The null pointer is not a valid memory address. However, I would like to believe that each decision is made for a reason, and those reasons are worth knowing.

    This rule simplifies the management of failure cases and other instances in which a pointer may be null. It is an easy, inexpensive check to make, and it adds appreciable convenience to the language.

    For example, if many conditions exist which would result in dynamic memory allocation, but others also exist which will not, it’s convenient to be able to just stick a delete at the end and not worry about it.

    // contrived example
    void foo(int n) {
        char *p = nullptr;
        switch(n) {
            case whatever:
            case something_else:
                p = new char[n];
                break;
        }
    
        // some code...
    
        delete [] p;  // look Ma, no check!
    }
    

    If delete nullptr were illegal then every call to delete would be surrounded by…

    if(ptr)
    

    …and that would be lame. Since this would be the norm, an essentially mandatory convention, why not just eliminate the need to check entirely? Why require an extra 5 characters (minimum) for every call to delete?

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

Sidebar

Related Questions

I remember reading somewhere (maybe someone can help remember where), that there is a
I remember reading somewhere about multi-column indexing in Core Data (iOS), but I can't
I remember reading somewhere that captured parameters in the url can be passed to
I remember reading somewhere that you can provide your own icons without having them
I remember reading somewhere that Hadoop's performance deteriorates significantly if the machines it runs
I may be completely off on this, but I swear I remember reading somewhere
I vaguely remember reading about this a couple of years ago, but I can't
I may be crazy, but I thought I remember reading that OnLoginError produces a
I remember reading somewhere that SQL Azure is going to terminate long-running queries. Is
I remember reading somewhere that Qt guarantees the size of some data types on

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.