print &p question..

This is a discussion on print &p question.. within the C Programming forums, part of the General Programming Boards category; i have a pointer p of int * type which p->value=7 so printf("%d",*&p); on the one hand &p is the ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    *&p == p

    so you printing value of p... and %d format is incorrect - you need to usee %p and cast p to void*
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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-20-2008, 11:58 PM
  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21