#include<stdio.h>
#define SIZE 3
int main()
{
char intArrayOne[SIZE] = {'A', 'B', 'C'};
char (*ptrToAnOneDimArray)[SIZE] = &intArrayOne;
int i = 0;
for(i=0 ; i<SIZE ; i++)
{
printf("%c ", (*ptrToAnOneDimArray)[i]);
}
}
Output
A B C
When should we use "ptrToAnOneDimArray" - kinds of usages in C/C++? Please give me a real-world example.
Can we avoid these kinds of complex and fuzzy usages of pointers?
For example, when you want to implement a dynamic multidimensional array:
is much better than
for various reasons (it does actually point to a 2D array that is contiguous in memory, it requires less allocations and frees, so it's less likely that you get it wrong, etc.)