This is an explanation about variables, pointers and arrays.
In C++, variables are stored in memory. Data in memory have values and addresses. CPUs don't know variable names, they only know memory addresses. When you compile your code, the compiler (actually, the linker) changes the variable name (a.k.a. symbol) to the actual memory address allocated for that variable. So when you retrieve the value of a variable in code, what actually happen is telling CPU the address, and CPU retrieve the data stored in that address of memory.
Addresses are just 32-bit or 64-bit (based on your CPU architecture) unsigned integers. So variables can also contain the addresses of other variables, which is called pointers. Pointers are also variables, the only difference is that pointers are 32-bit or 64-bit unsigned integers whose data is the address of other places.
When you declare a variable like float *a
, that means a
is a pointer to a variable of type float
. So the value of a
is not float number, but an unsigned integer. To change the location where a
is pointing at, just assign value to a
like a = &my_float_var;
. Notice that I use &
to get the address of variable my_float_var
.
As for arrays, they are just multiple variables allocated adjacent to each other. For example, we declare an array int arr[10]
, and say the address of the first element arr[0]
is 100
, then the address of second element arr[1]
is 104
(an int
is 4 bytes, address is measured in bytes). If you put arr
without bracket in code, that means the address of the array, i.e. the address of the first element.
You can see that arrays and pointers are similar. You can declare char arrays like:
char str1[] = "some string";
char *str2 = "some string";
Both method is fine. Only str1
is a symbol and you can't alter its value (the location where it's pointing at), but you can change str2
's value, making it pointing to another string.
Back to your question, Item **queue
can be though as a pointer of type Item *
, or an array of type Item *
. And type Item *
can be pointer of type Item
, or array of type Item
.
So if queue
is an array of type Item *
, while each element of that array points to another array of type Item
, queue
can be thought of a 2d array. But that's different from conventional 2d arrays. Conventional 2d array use syntax of arr[1,2]
to access elements, but accessing queue
's element should use queue[1][2]
.