I study pointers and challenge myself. I tried to dereference a pointer to an array of characters. In the end, it worked:
char (*p)[sizeof(c)];
Where c is an array of c [] = "something"
Itβs hard for me to understand how (*p)[sizeof(c)];
different from *p[sizeof(c)];
Based on what I currently know (which is not enough!), The computer says this in the case of (*p)[sizeof(c)];
:
"p points to c! oh, and btw, p is an array of any sizeof (c) value ending with".
But even this seems strange to me, so I think I'm confused by what is created when the brackets are added.
Can someone explain?
Full code in context:
#include <iostream> using namespace std; int main(int argc, char *argv[]) { char c[] = "something"; char (*p)[sizeof(c)]; // this works // char *p[sizeof(c)]; // this doesn't? p = &c; cout << p << endl; cout << *p << endl; }
source share