"Please tell me the difference between functions accepting arrays using single, double or triple pointers."
Arrays (int[]
for example) will change to (int*
) during compile time...
For example, take an integer int some_num = 10;
Now what would you do when you suddenly want to store these numbers as an array, of course int[] some_num_array = { some_num, some_num2, some_num3 };
<-- This is the most general method to do this...
If you know about vectors, then the vector equivalent would be: std::vector<int> some_num_array{ some_num, some_num2, some_num3 }
...
And you probably already know what a vector does, it is a container that stores values inside it and of course it can never store infinite value since it eats up your memory and will become as large as your memory can handle...
This, int*** A
that you have asked, can be interpreted as std::vector<std::vector<std::vector<int>>>
...
As you can already see, it is a vector containing vectors of vectors...
Then, the same way, it is a pointer containing pointers of pointers as well...
The reference operator (&) is used to convert a pointer to a super-pointer and so-on... And in C/C++ referencing means to allow other members and functions to assign a value to a variable (Remember! You can never assign to a variable, ever!)...
If we would try to convert our number some_num
above to an int***
, it means converting a non-pointer variable to a 3-level pointer that will have 5 as its value... auto A = new int**(new int*(&some_num));
So in other words, int***
can be termed as a three-dimensional pointer (array), just like you have seen a two-dimensional array storing columns inside its rows (indices).
A three-dimensional array, on the other hand, stores multiple two-dimensional arrays inside itself (sides)...
"*What does ***A mean?*"
Here, you can confuse people with a term which is known a dereferencing and does quite the opposite of referencing, the fact which we were talking about all this time... it dereferences (reducing [Hence, usage of de inside the term] the so-called pointer-level one-by-one)...
Like so, some_num = ***A;
, which just stores the value of A inside some_num
But, ***A = some_num;
, on the other hand, is different, it changes the value of A anywhere but NOT the pointer itself, that is the reason why (const char)*
cannot be dereferenced for assignment, since its dereferenced value is a constant character, which is a constant...... (inside or outside the function)
So, lastly, I would conclude by saying that the usage of pointers is either to be able to dereference its value (modifying the value, but not the pointer) or creating an array of a memory-based limit of levels of pointers...