|
A raw pointer points to an object in memory. It has no size/dimensional information beyond what you can sneak into the code as a hint to the compiler.
int myArray [10][20]; is an array, lets say. If you define a function thusly:
void myFunc (int a [][20]) and call it thusly:
myFunc (myArray);, a pointer to myArray gets passed. If you define it, rather, as:
void myFunc (int *a) and call it,
myFunc (myArray);, the exact same pointer gets passed.
It contains no size/dimension information; you need to pass that as an additional argument. HOWEVER, the first definition is a hint to the compiler that the lowest dimension is 20. Therefore, inside the function, ptr++ will increment by 20 integers. In the second example, it will increment by one integer. The first definition implies that it is a pointer to an ARRAY OF INTS, whereas the second implies that it is a pointer to int.
It's important to separate in your mind what information contained in your code causes explicit actions in the emitted machine code, and what information is a hint or implicit suggestion regarding the code to be emitted.
One cannot assign an array of char directly. One must do it piecemeal. Nevertheless, the syntax,
char myArray [10] = "Abcd"; certainly appears to be doing that.
It isn't, in the real sense that the emitted code is doing it. The compiler is merely being nice to you in a way that may confuse you when you get beyond an operation that can be done for you at compile time, contrasted to what may be done for you at run time.
|