+ 1

Doubt in Queue Management code in C++

This is what I understand: queue is initialised as a pointer. Then it is given a memory location in the heap for holding an array using new. This is what I don't understand: When queue is a pointer, how can we write queue[i] and perform other functions on it without derefencing it. So shouldn't we use *queue[i] instead? Help me understand this, please. Thank You https://code.sololearn.com/cPBr66cOIjtR/?ref=app

15th May 2021, 2:09 PM
Kaushik Nandan
Kaushik Nandan - avatar
2 Respostas
+ 1
queue[0] is the same thing as *queue. The [0] specifies the contents at offset 0. Just like you could use queue[5] or alternatively *(queue + 5).
15th May 2021, 2:33 PM
Jerry Hobby
Jerry Hobby - avatar
0
Jerry Hobby Is this just for arrays?
15th May 2021, 4:26 PM
Kaushik Nandan
Kaushik Nandan - avatar