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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:18:21+00:00 2026-06-07T09:18:21+00:00

I was reading the C++ FAQ – 8.6 – When should I use references,

  • 0

I was reading the C++ FAQ – “8.6 – When should I use references, and when should I use pointers?” and in particular this statement:

Use references when you can, and pointers when you have to.

…

The exception to the above is where a function’s parameter or return value needs a “sentinel” reference — a reference that does not refer to an object. This is usually best done by returning/taking a pointer, and giving the NULL pointer this special significance (references must always alias objects, not a dereferenced NULL pointer).

From what I’ve seen, the need for a “sentinel” reference is indeed often the reason to use pointers instead of references. What I’m wondering is: why doesn’t C++ have a special “NULL value” for references? It seems it would make pointers almost unnecessary, which would solve many problems.

So why wasn’t it part of the language specification?

Edit:

I’m not sure my question is clear – I guess I’m not asking litterally about NULL references. Most often I read that in C++ “the reference is the object”. And, in most OOP languages, objects can be NULL – Pascal, C#, Java, JavaScript, PHP, etc. in all these you can do someObject = null or someObject := nil. In fact, Pascal also supports pointers but still allows objects to be nil, since it has its use. So why is C++ somehow special and doesn’t have a NULL object? Was it just an overlook or an actual decision?

  • 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-07T09:18:23+00:00Added an answer on June 7, 2026 at 9:18 am

    Because a reference carries the semantic that it points to a valid memory address that never changes; i.e. that dereferencing it is safe/defined and so no NULL checks are required. References cannot be reassigned by design.

    You use a pointer when the var can be NULL and client code has to handle that case. You use a reference when you can guarantee a valid/initialised memory address.

    One example of using pointers is as a member of a class to store a “reference” to some instance that might not be known or able to be initialised at class construction time. However, member references must be initialised at construction time (via initialiser lists) and their assignment cannot be deferred.

    If you allow a null reference it is then no different to a pointer besides syntax (the same NULL checks would need to take place.)

    Update:

    “And, in most OOP languages, objects can be NULL – Pascal, C#, Java, JavaScript, PHP, etc. […] So why is C++ somehow special and doesn’t have a NULL object? Was it just an overlook or an actual decision?”

    I think you are a bit confused about this. Java and C# etc. might give the impression of “NULL objects”, but these object references are more or less like a C++ pointer with simpler syntax, GC instrumentation and exception throwing. In those languages if you operate on a “Null Object” you will get some kind of exception like NullReferenceException (C#). Hell, in Java its called a NullPointerException.

    You have to check for null before you can use them safely. Kind of like C++ pointers (except in most managed languages, pointers are initialised to NULL by default, whereas in C++ its usually up to you to take care of setting the initial pointer value (otherwise undefined/whatever memory was already there)).

    The C++ view is about having choice, and hence being verbose:

    • Use a plain pointer to do how you please, checking NULL where necessary.
    • Use references which have a compiler-enforced validity semantic/constraint.
    • Roll your own smart pointers that do bookkeeping and behave whichever way you want them to.
    • Using void pointers (cautiously!) to reference an untyped block of memory if ever required.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The usocket FAQ suggests that the way I should do this is by reading
I was reading the SQLite FAQ , and came upon this passage: Threads are
I was reading the C++0x FAQ by Stroustrup and got stuck with this code.
I am coming back from after reading this c-faq question I am totaly confused
After reading the faq's and everything else I can find, I'm still confused. If
I have been reading through the C++ FAQ and was curious about the friend
I was just reading the section of the C FAQ on pointers . It
While reading up on SQLite, I stumbled upon this quote in the FAQ: Threads
After reading monkeytalk faq from http://www.gorillalogic.com/testing-tools/monkeytalk/documentation/monkeytalk-faq : How does it all work? MonkeyTalk is
I was reading WCF .NET 4 faq. I'm not sure with the answer for

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.