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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:36:38+00:00 2026-06-06T18:36:38+00:00

Possible Duplicate: Is NULL always zero in C? Following code: char *p1 = 0;

  • 0

Possible Duplicate:
Is NULL always zero in C?

Following code:

char *p1 = 0;
char *p2 = NULL;
char *p3 = (char *)0;

if (NULL == 0)
    printf("the NULL is same as 0\n");

printf("0 : %s\n", 0);
printf("p1 : %s\n", p1);
printf("p1 : %x\n", p1);
printf("&p1 : %x\n", &p1);

printf("NULL : %s\n", NULL);
printf("p2 : %s\n", p2);
printf("p2 : %x\n", p2);
printf("&p2 : %x\n", &p2);
printf("*p2 : %s\n", *p2);

output:

the NULL is same as 0
0 : (null)
p1 : (null)
p1 : 0
&p1 : bf9a0204
NULL : (null)
p2 : (null)
p2 : 0
&p2 : bf9a0208
Segmentation fault (core dumped)

I wonder:

What the (null) stands for?

Does the pointer p1 or p2 point to address 0x0?

Does the statement printf(“p1 : %x\n”, p1); outputs p1 : 0 indicates p1 point to address 0x0?

  • 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-06T18:36:39+00:00Added an answer on June 6, 2026 at 6:36 pm

    All these initializatiions

    char *p1 = 0;
    char *p2 = NULL;
    char *p3 = (char *)0;
    

    are equivalent. All of them initialize these pointers with null-pointer value of type char *. The physical representation of that null-pointer value is platform-dependent. It is not guaranteed to be represented by physical 0x0 address. There’s no way to say what physical address they will “point to” in general.

    On your platform null-pointer value happens to be represented by physical address 0x0, judging by the output. However, the proper way to print a pointer value with printf is to either use %p format specifier, or by converting the pointer value to a suitable integral type. Using %x to print pointers leads to undefined behavior.

    The (null) output that you see is the reaction of printf to your attempt to use %s specifier with null pointers. This leads to undefined behavior, but your implementation of standard library apparently decided to save your from worse fate and print (null) instead.

    In fact, every single printf statement in your code sample is composed incorrectly, each leading to undefined behavior.

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

Sidebar

Related Questions

Possible Duplicate: C# okay with comparing value types to null Consider the following code
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: Resizing an Image without losing any quality The code I always use
Possible Duplicate: Android 2.1 View's getDrawingCache() method always returns null I hava a Layout
Possible Duplicate: /dev/null in Windows? I have a complex code that encodes input file
Possible Duplicate: error: ‘NULL’ was not declared in this scope i'm having this 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
Possible Duplicate: What is wrong in comparing a null with an object rather than

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.