Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Pointer/ array question

  1. Oct 14, 2008 #1
    Code (Text):

    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

    printf("%d\n", array);

    will it make any difference?
  2. jcsd
  3. Oct 14, 2008 #2


    User Avatar
    Homework Helper

    printf("...", array) is actually read as:
    printf("...", &array[0]);

    So that prints out the memory address of the first array index.
  4. Oct 14, 2008 #3
    &integer =the address of the variable ?
  5. Oct 14, 2008 #4


    User Avatar

    Staff: Mentor

    &variable = addres of the variable regardless if its type.
  6. Oct 14, 2008 #5
  7. Oct 15, 2008 #6


    User Avatar
    Homework Helper

    Note that structures work differently.

    Code (Text):

    typedef struct {arrayofints[5];}SAI;

    static SAI sai0 = {1,2,3,4,5};
    static SAI sai1;

    int main()
        sai1 = sai0;    // copies entire structure
    I do recall that some older C compilers treated arrays the same as structures are handled now, but it's not part of the C language now (I don't know what if anything changed between the orignal C language and what exists today).
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook