Re: [PIC] Learning C
smplx <[email protected]>
| Newsgroups | gmane.comp.hardware.microcontrollers.pic |
|---|---|
| Message-ID | <[email protected]> |
On Wed, 20 Nov 2024, Forrest Christian (List Account) wrote: > Things got a lot clearer when I finally realized that there is absolutely > no difference to the compiler between: > > x=array[i] > > And: > > x=*(array+i) > > The same is true for a pointer... you can use ptr[i] interchangeably with > *(ptr+i) . I concur but this can be confusing for a novice that doesn't understand that "i" gets scaled based on the type of array. If you have an array of structures this could involve doing a multiply in software. > > Once they're defined, the only difference between an array and a pointer is > that you can't change the address of an array (its determined by the > compiler), but the address a pointer points at can be changed at will. > Actually there is another difference between an array and a pointer: it is the same as the difference between a constant and a variable. try writing some PIC16 assembler to get the value of arr[j] for all four cases where arr is defined as a label and also as a pointer ***AND*** where j is defined as a constant and as a variable. Friendly Regards Sergio Masci