samedi 11 juillet 2020

Why does the index of a `char **` type give the whole string?

Consider this snippet:

#include <iostream>

using std::cout;
using std::endl;

int main()
{
    char c[] = {'a','b','c','\0'};
    char *pc = c;
    char **ppc = &pc;
    cout << ppc[0] << endl;
}

This prints abc as output. Why does the index of a pointer to pointer to char return the whole string? Here, ppc only points to another pointer that points to a single char. How does it know about the whole string and why would it return it?

Aucun commentaire:

Enregistrer un commentaire