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 785411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:52:26+00:00 2026-05-14T20:52:26+00:00

In C (or C++ for that matter), pointers are special if they have the

  • 0

In C (or C++ for that matter), pointers are special if they have the value zero: I am adviced to set pointers to zero after freeing their memory, because it means freeing the pointer again isn’t dangerous; when I call malloc it returns a pointer with the value zero if it can’t get me memory; I use if (p != 0) all the time to make sure passed pointers are valid, etc.

But since memory addressing starts at 0, isn’t 0 just as a valid address as any other? How can 0 be used for handling null pointers if that is the case? Why isn’t a negative number null instead?


Edit:

A bunch of good answers. I’ll summarize what has been said in the answers expressed as my own mind interprets it and hope that the community will correct me if I misunderstand.

  • Like everything else in programming it’s an abstraction. Just a constant, not really related to the address 0. C++0x emphasizes this by adding the keyword nullptr.

  • It’s not even an address abstraction, it’s the constant specified by the C standard and the compiler can translate it to some other number as long as it makes sure it never equals a “real” address, and equals other null pointers if 0 is not the best value to use for the platform.

  • In case it’s not an abstraction, which was the case in the early days, the address 0 is used by the system and off limits to the programmer.

  • My negative number suggestion was a little wild brainstorming, I admit. Using a signed integer for addresses is a little wasteful if it means that apart from the null pointer (-1 or whatever) the value space is split evenly between positive integers that make valid addresses and negative numbers that are just wasted.

  • If any number is always representable by a datatype, it’s 0. (Probably 1 is too. I think of the one-bit integer which would be 0 or 1 if unsigned, or just the signed bit if signed, or the two bit integer which would be [-2, 1]. But then you could just go for 0 being null and 1 being the only accessible byte in memory.)

Still there is something that is unresolved in my mind. The Stack Overflow question Pointer to a specific fixed address tells me that even if 0 for null pointer is an abstraction, other pointer values aren’t necessarily. This leads me to post another Stack Overflow question, Could I ever want to access the address zero?.

  • 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-05-14T20:52:27+00:00Added an answer on May 14, 2026 at 8:52 pm

    2 points:

    • only the constant value 0 in the source code is the null pointer – the compiler implementation can use whatever value it wants or needs in the running code. Some platforms have a special pointer value that’s ‘invalid’ that the implementation might use as the null pointer. The C FAQ has a question, “Seriously, have any actual machines really used nonzero null pointers, or different representations for pointers to different types?”, that points out several platforms that used this property of 0 being the null pointer in C source while represented differently at runtime. The C++ standard has a note that makes clear that converting “an integral constant expression with value zero always yields a null pointer, but converting other expressions that happen to have value zero need not yield a null pointer”.

    • a negative value might be just as usable by the platform as an address – the C standard simply had to chose something to use to indicate a null pointer, and zero was chosen. I’m honestly not sure if other sentinel values were considered.

    The only requirements for a null pointer are:

    • it’s guaranteed to compare unequal to a pointer to an actual object
    • any two null pointers will compare equal (C++ refines this such that this only needs to hold for pointers to the same type)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do any of the IDEs (or any other tool for that matter) have the
I've got a PHPUnit mock object that returns 'return value' no matter what its
How can I efficiently and effectively detect the version and, for that matter, any
Does it matter to developers that the current, and newer versions of .Net don't
Exactly that: Does a strings length equal the byte size? Does it matter on
In .Net (VB more specifically, but that doesn't really matter), is there a way
I have a python logger set up, using python's logging module. I want to
I have quicktime movies uploaded to my server that I need to combine together
Ok: This is some of my table structure that matters here CaseStudyID int Title
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business

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.