Ok, while reading my book on D3D10, I noticed that the last two parameters of the D3D10CreateDeviceAndSwapChain function were a pointer to a pointer. Like **device and the book said "returns the device". I don't think this just applies to D3D, so why would I pass a pointer to a pointer (**foo) as a parameter?
Copyright © 2024 QUIZLS.COM - All rights reserved.
Answers & Comments
Verified answer
Well, think about it. Why would you pass a pointer? You would pass a pointer if you needed to directly modify the contents at that address. So if you are passing a pointer to a pointer, it's because you want to modify a pointer to point to something else. i.e.
void PointElsewhere(int ** ipp)
{
int * ip = new int;
*ipp = ip;
}
int main()
{
int x;
int * xp = &x;
// xp holds the address of x
void PointElsewhere(&xp);
// now xp holds the address of the int created in that function
return 0;
}
This wasn't a particularly useful example. But it's useful if you are dealing with an array of pointers, or an array of arrays.