A Few Words About Pointers in C.
When learning C, beginners often have questions about pointers. I think everyone has roughly the same questions, so I'll describe the ones I had.
What is a pointer for?
Why do people always write "pointer to type", and how does a pointer to uint16_t differ from a pointer to uint8_t?
And who invented pointers anyway?
Before answering these questions, let's recall what a pointer is.
A pointer is a variable that contains the address of some data element (a variable, constant, function, structure).

To declare a variable as a pointer, put * before its name, and to get the address of a variable use & (the unary address-of operator).
In this case p contains the address of variable a. But interestingly, to keep working with the pointer you don't need to write the asterisk; it's only needed in the declaration.
In this case p contains the address of variable b, but if we want to get the value stored at this address, we need to use the dereference operator, the same asterisk *.
Thus the variable new_simbol will contain the ASCII code of the character 'a'.
Now let's get to the questions themselves: what is a pointer for? Imagine we have an array that we want to work with in a function. To pass an array to a function by value, it would have to be copied, i.e. using memory, of which the MCU has little anyway, so a better solution is not to copy the array but to pass the address of its first element and its size.
You can do it like this
or like this
Since the name of an array contains the address of its first element, it is nothing other than a pointer. You can move through the array with simple arithmetic operations; for example, to get the value of the fifth element of the array, add 4 to the address of the array (the address of the first element) and apply the dereference operator.
And then the question immediately arises: why does everyone write a type before the pointer? It's simple: by passing the address of the first element of the array and its size, we're saying: dig 10 holes (the array size) starting from here (the pointer). We come back two hours later, and those who were supposed to dig the holes have called a bulldozer and are digging a foundation pit. To avoid such a situation, we should have specified the size of a hole, which in our analogy is the pointer type, since the type determines how many bytes a variable takes up in memory.
So by specifying the pointer type, we tell the compiler: here is the start address of the array, one element of the array takes 2 bytes, there are 10 such elements in the array; so how much memory should be allocated for this array? 20 bytes, the compiler answers. For clarity, let's take a void pointer, for which the size it occupies is not defined; it's just an address. We'll cast it to pointers of different types and dereference them.

You can also pass a pointer to a structure to a function. Since the layout of the structure is known, it's enough to pass only the address of its beginning, and the compiler will split it into fields itself.
And the last question: who inventedthis nasty thing the pointer? To figure this out, we need to turn to assembly, for example AVR assembly, and there we'll find the instructions
It becomes clear that X contains a pointer (an address), and it turns out there's no evil man who invented pointers to confuse everyone; working with pointers (addresses) is supported at the level of the MCU core.
What is a pointer for?
Why do people always write "pointer to type", and how does a pointer to uint16_t differ from a pointer to uint8_t?
And who invented pointers anyway?
Before answering these questions, let's recall what a pointer is.
A pointer is a variable that contains the address of some data element (a variable, constant, function, structure).

To declare a variable as a pointer, put * before its name, and to get the address of a variable use & (the unary address-of operator).
char a = 'a';
char *p = &a;
In this case p contains the address of variable a. But interestingly, to keep working with the pointer you don't need to write the asterisk; it's only needed in the declaration.
char a = 'a';
char b = 'b';
char *p = &a;
p = &b;
In this case p contains the address of variable b, but if we want to get the value stored at this address, we need to use the dereference operator, the same asterisk *.
char new_simbol = 0;
char a = 'a';
char *p = &a;
new_simbol = *p;
Thus the variable new_simbol will contain the ASCII code of the character 'a'.
Now let's get to the questions themselves: what is a pointer for? Imagine we have an array that we want to work with in a function. To pass an array to a function by value, it would have to be copied, i.e. using memory, of which the MCU has little anyway, so a better solution is not to copy the array but to pass the address of its first element and its size.
m[100] ={1,2,3...};You can do it like this
void foo(char *m, uint8_t size)
{
}or like this
void foo(char m[], uint8_t size)
{
}Since the name of an array contains the address of its first element, it is nothing other than a pointer. You can move through the array with simple arithmetic operations; for example, to get the value of the fifth element of the array, add 4 to the address of the array (the address of the first element) and apply the dereference operator.
m[4] = *(m + 4);And then the question immediately arises: why does everyone write a type before the pointer? It's simple: by passing the address of the first element of the array and its size, we're saying: dig 10 holes (the array size) starting from here (the pointer). We come back two hours later, and those who were supposed to dig the holes have called a bulldozer and are digging a foundation pit. To avoid such a situation, we should have specified the size of a hole, which in our analogy is the pointer type, since the type determines how many bytes a variable takes up in memory.
So by specifying the pointer type, we tell the compiler: here is the start address of the array, one element of the array takes 2 bytes, there are 10 such elements in the array; so how much memory should be allocated for this array? 20 bytes, the compiler answers. For clarity, let's take a void pointer, for which the size it occupies is not defined; it's just an address. We'll cast it to pointers of different types and dereference them.

You can also pass a pointer to a structure to a function. Since the layout of the structure is known, it's enough to pass only the address of its beginning, and the compiler will split it into fields itself.
And the last question: who invented
st X, r1 ;store the contents of r1 in SRAM at address X, where X is the register pair r26, r27
ld r1,X ; load into r1 the contents of SRAM at address X, where X is the register pair r26, r27
It becomes clear that X contains a pointer (an address), and it turns out there's no evil man who invented pointers to confuse everyone; working with pointers (addresses) is supported at the level of the MCU core.