Thread: pointer/ array question..

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

    pointer/ array question..

    Code:
    printf("%p\n", array);
    i know that unlike other variables
    when we want to do some operation on an array
    it uses the physical address of the array

    but there are many cells in the array
    does it prints every one of them??

    does the array always defined as pointer ??
    even if we make every cell as int
    Last edited by transgalactic2; 10-14-2008 at 04:55 AM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The compiler will pass an array as a pointer to the first element when passing it to a function. In this case, the function is printf, but it makes no difference to how the array is passed. It will show you the address of the first element of the array.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > does it prints every one of them??
    Try it for yourself... that'd be a no

    > does the array always defined as pointer ?? even if we make every cell as int
    Yes. But you should be casting to (void *) as "%p" requires (which may be implicit, but being explicit is always good).

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Huh?

    Because printf() allows a variable-number-of-arguments, I don't think the user's variable types can be checked against some expected prototype. Somewhere it is said that a pointer is a pointer is a pointer (its footprint, not "pointer arithmetic"), so stacking pointers to the printf() function will be safe, and always syntactically error free.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I don't think it's a size issue; it's just that %p prints "void *". It's not guaranteed to print anything else. Of course it does, for the reasons you mentioned.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer of array of class
    By 11moshiko11 in forum C++ Programming
    Replies: 5
    Last Post: 04-05-2008, 09:58 AM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  3. array pointer question
    By Hoser83 in forum C Programming
    Replies: 5
    Last Post: 02-03-2006, 11:19 AM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  5. A question between Array and Pointer
    By Unregistered in forum C++ Programming
    Replies: 16
    Last Post: 08-05-2002, 09:13 AM