dimanche 7 février 2021

Pointer of array, what is the difference between (*ptr)[] and *ptr[]

I'm a beginner of c++, I met a wield thing when I tried to understand the pointer of array

#include <iostream>

int main() {
    using namespace std;

    short tell[3]{1, 2, 3};

    short (*pas)[3] = &tell;

    cout << (*pas)[2] << endl;
    cout << *pas[2] << endl;

    cout << endl;

    return 0;
}

However, I got two different values for the two outputs.

The first one is correct, which is 3.

However, for the second one, seems it returns a random number which is different every time.

SO, what is the difference between these two?

Aucun commentaire:

Enregistrer un commentaire