About the C++ array and the addition of byte variables?

Asked 2 years ago, Updated 2 years ago, 87 views

I am a beginner in C++ language.
There is a part where the byte type array is added to a certain source code.
I had no idea what I was doing.
Below are excerpts of the relevant parts:

byte arduino[8];
memset(arduino, 0xFF, size of (arduino));
The byte uno=something;//← byte variable uno contains 0b000 to 0b111 (0 to 7).
byte*input=arduino+uno;//← I don't know what I'm doing on this line.

I wish someone could explain it to me.

c++ array

2022-09-30 11:33

2 Answers

byte is not a standard type, so assume it is an integer type.

If you use an array variable alone, it returns the address of the element at the beginning of the array.In this case, arduino returns the address of the leading element arduino[0], or &arduino[0].

If you add an integer value to it, that value will be the address of the element to which the element in the array has been skipped.For example, if you add 3, the address &arduino[3] of the three elements If you add 0, you will skip nothing, so &arduino[0].

This time code
byte*input=arduino+uno;
In , if uno contains 3, input contains &arduino[3].If you set this to *input later, you get the same effect as arduino[3].


2022-09-30 11:33

byte*input=arduino+uno;

byte*input=&arduino[uno];.

arduino is the first address of the array, from which the unoth data address.
uno is declared by byte, but int is sufficient.(No benefit of byte)
Rather than C++, I think it's C.


2022-09-30 11:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.