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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:44:35+00:00 2026-06-18T12:44:35+00:00

I am writing a code to read the address of the node in linked

  • 0

I am writing a code to read the address of the node in linked list so can some one confirm if %p and %u format in printf is correct. One gives me the hex and other gives me a decimal and conversion to hex or deci are matching. Also it will be great if someone can brief on difference of %p and %u.

struct node {
    int x;
    struct node *next;
};

int main () {
    struct node *root;
    struct node *track;

    root = malloc(sizeof(struct node));
    printf ("Location of root is %p\n", root);
    printf ("Location of root is %u\n", root);
}

Output of execution:

[root@vm c_prog]# ./a.out 
Location of root is 0xdc3010
Location of root is 14430224
[root@vm c_prog]# ./a.out 
Location of root is 0x11fbf010
Location of root is 301723664
[root@vm c_prog]# ./a.out 
Location of root is 0x7e8e010
Location of root is 132702224
[root@vm c_prog]# 
  • 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-18T12:44:36+00:00Added an answer on June 18, 2026 at 12:44 pm

    %p is for a pointer, and is correct. Strictly speaking, you should cast to void *, but I’ve never met an implementation that cared. Example:

    printf ("Location of root is %p\n", (void *)root);
    

    %u is for an unsigned int and is not correct, unless you play some casting gymnastics and are sure a pointer and an int are the same size. To safely print a pointer value in decimal, you should use PRIuPTR from inttypes.h:

    printf ("Location of root is %"PRIuPTR"\n", (uintptr_t)root);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While writing some C code, I decided to compile it to assembly and read
I am writing some code to read an excel file, but unfortuantely the excel
I'm writing code to read in a 7x15 block of text in a file
Code is read more often then updated. Writing more readable code is better than
i am writing a code to handle read/unread messages, with a simple user_id/message_id mysql
I am writing an app where I need to read the Address Book data
I'm writing GC friendly code to read and return to the user a series
I am writing some embedded code to interface with an external device over SPI.
I am writing a generic test function that will accept a function address (read
I'm writing a code for a MIPS pipeline simulator in C++. One of my

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.