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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:33:22+00:00 2026-06-13T20:33:22+00:00

Possible Duplicate: Is NULL always zero in C? The C standard states the following

  • 0

Possible Duplicate:
Is NULL always zero in C?

The C standard states the following for calloc():

The calloc function allocates space for an array of nmemb objects, each of whose size is size. The space is initialized to all bits zero.

with the following caveat relating to all bits zero:

Note that this need not be the same as the representation of floating-point zero or a null pointer constant.

Test program:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main()
{
    char** list = calloc(10, sizeof(*list));
    int i;
    for (i = 0; i < 10; i++)
    {
        printf("%p is-null=%d\n", list[i], NULL == list[i]);
    }
    free(list);

    return 0;
}

I built and executed this program with the following compilers:

  • VC7, VC8, VC9, VC10
  • gcc v4.1.2, gcc v4.3.4
  • Forte 5.8, Forte 5.10

In all cases all bits zero is a NULL pointer (unless I made a mistake in the test program).

What is the reason a NULL pointer is not guaranteed by the C standard to be all bits zero ? Out of curiousity, are there any compilers where all bits zero is not a NULL pointer ?

  • 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-13T20:33:23+00:00Added an answer on June 13, 2026 at 8:33 pm

    The com.lang.c FAQ answers this in question 5.16, where it explains why this happens, and question 5.17, where it gives examples of actual machines with nonzero NULL. A relatively “common” case is for address 0 to be valid, so a different invalid address is selected for NULL. A more esoteric example is the Symbolics Lisp Machine, which does not even have pointers as we know them.

    So it’s not really a question of choosing the right compiler. On a modern byte-addressable system, with or without virtual memory, you are unlikely to encounter a NULL pointer that is not address 0.

    The C standard is carefully designed to accommodate hardware that is downright bizarre, and this is just one the results. Another weird gotcha along the same lines is that it’s possible for sizeof(void *) != sizeof(int *), but you’ll never see it happen on a byte-addressable architecture.

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

Sidebar

Related Questions

Possible Duplicate: Is NULL always zero in C? Following code: char *p1 = 0;
Possible Duplicate: Setting Objects to Null/Nothing after use in .NET Do you need to
Possible Duplicate: What will happen when I call a member function on a NULL
Possible Duplicate: Exception is NULL always I've got a strange problem with an IOException
Possible Duplicate: Android 2.1 View's getDrawingCache() method always returns null I hava a Layout
Possible Duplicate: Do you use NULL or 0 (zero) for pointers in C++? Is
Possible Duplicate: C# okay with comparing value types to null Consider the following code
Possible Duplicate: C#: Passing null to overloaded method - which method is called? Here
Possible Duplicate: Case Order by using Null I'm looking to get a list of
Possible Duplicate: How to eliminate NULL fields in TSQL I am using SSMS 2008

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.