1. meera

    Thread Starter New Member

    Jun 7, 2007
    6
    0
    i'm using c to write program for microchip microcontroller.

    recently i come across with one program from internet which i confuse with one of the code

    normally for array in c, i just write
    bitmap[]={5,5,5};
    temp=bitmap[0]-1; then i get temp=4;

    but now i saw from the code, it's written there
    temp1=bitmap;
    temp2=bitmap-1;

    may i know what's mean by bitmap-1?(just the array name)

    i try to run some simple simulation for the code, i get the answer
    temp1=10;
    temp2=9;

    but i don't understand where its value come from.

    thanks.
     
  2. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    I'm guessing it's using pointers, but without seeing the rest of the code and specifically the variable declarations, it is only a guess..
     
  3. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    It is indeed using pointers. The name of any array is in fact a pointer to the first element of that array if you have an array test[];
    then a = test[0]; and a = test; will produce the same result.
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,179
    1,800
    The syntax and semantics came from the original K&R. Specifically, an array name, foo, was to be interpreted as:

    &foo[0]

    or in other words the address of the first element in the array.
     
  5. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    Yes, but it cannot be the array name -1, that would be one element below the start of the array.

    It would only make sense with a pointer used within the array.
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,179
    1,800
    Depends on the presence or absence of array bounds checking. In the freewheeling early days it was unlikely to be there. Such things can very occasionally be useful but more often than not are a source of great pain and frustration. Evaluating such an expression is probably benign; deferencing is probably not benign
     
  7. meera

    Thread Starter New Member

    Jun 7, 2007
    6
    0
    thanks a lot to all of your reply.
    yup, the result is represent address of the pointer 1st array..i check it on FileRegister and get the answer.

    Thanks
     
Loading...