Variable types with * prefix

ogram execution.

I think that this is hair splitting. Everyone knows what those terms mean, but let's give them a definition anyway:

  • Declaring a variable = reserve a piece of memory for it and give tihs memory a name.
  • Defining a variable = telling the compiler that a variable of a certain type (amount of memory) is going to be used but the memory itself is not allocated yet.
  • Assigning the variable = copying some value into variable's memory space.
  • Initializing the variable = assigning it a value for the first time.

I don't think that clarifies anything. Back to your question, what would the following code do?

`byte *ptr;

*ptr = 0x35;`

Most likely crash the controller, since ptr's value is undefined (haven't been allocated yet) and point to, well, whatever was in the memory that ptr occupies before this memory was assigned to ptr. So ptr may point to any location of the memory until it gets properly assigned with some address. So it is a bad idea to do something like this.

But, once again, does this question have a point?

2 Likes