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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:13:33+00:00 2026-05-20T10:13:33+00:00

I reading a C book. To print out a memory address of a variable,

  • 0

I reading a C book. To print out a memory address of a variable, sometimes the book uses:

printf("%u\n",&n);

Sometimes, the author wrote:

printf("%d\n",&n);

The result is always the same, but I do not understand the differences between the two (I know %u for unsigned).

Can anyone elaborate on this, please?

Thanks a lot.

  • 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-20T10:13:33+00:00Added an answer on May 20, 2026 at 10:13 am

    %u treats the integer as unsigned, whereas %d treats the integer as signed. If the integer is between 0 an INT_MAX (which is 231-1 on 32-bit systems), then the output is identical for both cases.

    It only makes a difference if the integer is negative (for signed inputs) or between INT_MAX+1 and UINT_MAX (e.g. between 231 and 232-1). In that case, if you use the %d specifier, you’ll get a negative number, whereas if you use %u, you’ll get a large positive number.

    Addresses only make sense as unsigned numbers, so there’s never any reason to print them out as signed numbers. Furthermore, when they are printed out, they’re usually printed in hexadecimal (with the %x format specifier), not decimal.

    You should really just use the %p format specifier for addresses, though—it’s guaranteed to work for all valid pointers. If you’re on a system with 32-bit integers but 64-bit pointers, if you attempt to print a pointer with any of %d, %u, or %x without the ll length modifier, you’ll get the wrong result for that and anything else that gets printed later (because printf only read 4 of the 8 bytes of the pointer argument); if you do add the ll length modifier, then you won’t be portable to 32-bit systems.

    Bottom line: always use %p for printing out pointers/addresses:

    printf("The address of n is: %p\n", &n);
    // Output (32-bit system): "The address of n is: 0xbffff9ec"
    // Output (64-bit system): "The address of n is: 0x7fff5fbff96c"
    

    The exact output format is implementation-defined (C99 §7.19.6.1/8), but it will almost always be printed as an unsigned hexadecimal number, usually with a leading 0x.

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

Sidebar

Related Questions

I am reading a book in which author used a code like this public
So I've been reading through the K&R C book and have a question.. in
So I wrote this function from a book I am reading, and this is
I'm reading Paul Carter's pcasm book. It uses NASM, a C driver app that
I've been reading Google Script and the book goes through several uses for Google
I am reading over the K&R book, and am a little stuck. What is
C really isn't my strong point and after reading 3 chapters of a book
Recently, I was reading book about Erlang which has hot deployment feature. The deployment
Reading a book I have found the following statement: (Object) Behaviors answer either of
While reading a book about JavaScript I stumbled across an example: var names =

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.