What does *(ptr++) = true/false do?

I'm trying to wrap my head around the use of pointers used in some open-source code I've been studying. Forgive me for loosely referencing the code rather than sharing the entire thing - it's a bit much to take in and my question is a straight forward one - I hope.

For this code the pointer is declared as a boolean value with;
boolean *ptr = byteArray; // let's pretend byteArray exists, which is an array of bytes

This pointer is used within a for loop like so;
for (byte b = 0; byte b < 4, byte b++)
{
*(ptr++) = true or false // a digitalRead result for this code
}

So what exactly is incrementing? Is it simply shifting what byte of the byteArray it's referencing and updating the LSB to a 0 or 1? (best I can guess)

I suppose I could keep tinkering with code to find out, but I'm working with a vague understanding so some clarity is much appreciated.

The pointer is dereferenced, then incremented.

The incorrectly formatted line of code would store four "true or false" values in four successive bytes.

it increment the pointer, so the next read will store to the next element of the byteArray array

no, it is no shift here. Each new value is stored in whole byte

ptr is post-incremented and then dereferenced, BUT

Post-increment and post-decrement creates a copy of the object, increments or decrements the value of the object and returns the copy from before the increment or decrement.

so dereferencing is happening on ptr before it is incremented

Then the compiler would throw an error. A 'bool *' is a different data type than a 'byte *'.

perhaps the "byteArray" is just the name of the array of booleans :slight_smile:

OP says array of bytes contrary to what they write

....
No compiler error and no array of booleans. It's an array of bytes.

Thanks for the quick responses. So *(ptr++) = true or *(ptr++) = false is creating a byte to store for every run of the for loop, correct?

My next question was how does this part function;
boolean *ptr = byteArray;

Since it's simply calling the variable name and not the position of a value within the array I'm not sure what value it would relay.

Maybe the byteArray is only storing 0 and 1 for the LSB so it can be observed as a boolean?

Again, no errors. The code works great. I'm simply trying to learn why it works so great and the use of pointers illudes me. I'd like to believe dark magic has no part here.

Post a complete code that compiles.
Post it properly with Code Tags.

what you posted won’t compile, so post the actual code you use

no. The bytes will not be "created", they just populated by true or false values. The array must be allocated in memory before this line.

Sure. Enjoy.

This line is defined ptr as pointer to boolean.
Value of the pointer ptr is assigned by the address of byteArray array.

boolean signals[KEYS_NUMBER * 2];

byte array, right?

Is there a facepalm emoj on here?
You're right... It's a boolean array.
There I said it.

:man_facepalming: :person_facepalming: :woman_facepalming:

Hey I just learned how to quote.

I'm not understanding what variable from the array it's storing. All of them?

Lol much appreciatted.

None.
The ptr will store the address of array rather than it's elements

Well that's confusing.
I thought something like "&ptr = booleanArray" would store the location rather than it's value and "*ptr = booleanArray" would store the value.

My understanding is limited to the the definitions of the "Pointer Access Operators"