Thread: print &p question..

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    print &p question..

    i have a pointer p of int * type
    which p->value=7

    so
    printf("%d",*&p);

    on the one hand &p is the address of p
    so our printf should print 7

    but on the other hand &p (points to pointer p)
    so its just like saying printf ("%d",p); which doesnt mean much

    which one of them is correct??

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    *&p == p

    so you printing value of p... and %d format is incorrect - you need to usee %p and cast p to void*
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. merging linked lists
    By scwizzo in forum C++ Programming
    Replies: 15
    Last Post: 09-14-2008, 05:07 PM
  2. Print out first N lines
    By YoYayYo in forum C Programming
    Replies: 1
    Last Post: 02-21-2008, 12:58 AM
  3. Exam Question - Possible Mistake?
    By Richie T in forum C++ Programming
    Replies: 15
    Last Post: 05-08-2006, 03:44 PM
  4. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM
  5. Question type program for beginners
    By Kirdra in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 05:10 AM