Thread: Printing the value of a pointer

  1. #1
    Registered User
    Join Date
    Oct 2014
    Posts
    6

    Question Printing the value of a pointer

    Hello,I'm trying to print the full value (in hexadecimal) of a pointer.This is my best attempt so far:
    Code:
    char *text = "\x10\x11\x12\x13\x14\x15\x16\x17";printf("%x", &text);
    And it obviously doesn't work, best I've gotten is a single byte, but I want the whole lot of bytes.Any ideas?Thanks for your time!

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Try %p
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    In this case, I think the problem description is flawed, and %p is not the solution.

    If the intent is to produce an output "1011121314151617" (without the quotes) then it is necessary to print every character of text individually using %x. However, describing that as "printing the full value of a pointer" is incorrect.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  4. #4
    Registered User user.beshi's Avatar
    Join Date
    Oct 2014
    Posts
    9
    Quote Originally Posted by sockets12 View Post
    Hello,I'm trying to print the full value (in hexadecimal) of a pointer.This is my best attempt so far:
    Code:
    char *text = "\x10\x11\x12\x13\x14\x15\x16\x17";printf("%x", &text);
    And it obviously doesn't work, best I've gotten is a single byte, but I want the whole lot of bytes.Any ideas?Thanks for your time!
    are you trying to print address where that pointer is or where it points or what it points? make it clear...

  5. #5
    Registered User
    Join Date
    Oct 2014
    Posts
    6
    Quote Originally Posted by grumpy View Post
    In this case, I think the problem description is flawed, and %p is not the solution.If the intent is to produce an output "1011121314151617" (without the quotes) then it is necessary to print every character of text individually using %x. However, describing that as "printing the full value of a pointer" is incorrect.
    Thanks! Doing a for loop and printing from there worked perfectly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printing from void pointer
    By africanwizz in forum C Programming
    Replies: 9
    Last Post: 05-27-2014, 03:33 AM
  2. pointer printing
    By c_lady in forum C Programming
    Replies: 10
    Last Post: 06-10-2010, 08:15 AM
  3. pointer printing
    By c_lady in forum C Programming
    Replies: 7
    Last Post: 05-18-2010, 09:50 AM
  4. printing dereferenced pointer.
    By olliepa in forum C Programming
    Replies: 8
    Last Post: 10-18-2009, 05:03 PM
  5. pointer printing
    By bandal27 in forum C Programming
    Replies: 13
    Last Post: 12-29-2008, 07:46 AM

Tags for this Thread