Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In an example for a little game framework (that does work), there are the lines:

ID3D10Device* device;
ID3D10Buffer* pBuffer;

followed by the line

 device()->CreateBuffer(&bd, NULL, &pBuffer());

The third argument requires a pointer, so why do you need to put an ampersand before pBuffer? an ampersand gets a memory address right? But pBuffer is already a pointer so what does the ampersand do to it?

share|improve this question
This probably belongs on StackOverflow, as it's not really game development related. Also, did you intend to write "device()" and "pBuffer()" in your third line? That seems like a typo; at the very least it changes the meaning of the code somewhat. – Josh Petrie Sep 23 '11 at 14:51
up vote 9 down vote accepted

As described in the ID3D10Device::CreateBuffer page, this function simply requires a pointer to a pointer which is used to contain the output of the function.

HRESULT CreateBuffer(
  [in]   const D3D10_BUFFER_DESC *pDesc,
  [in]   const D3D10_SUBRESOURCE_DATA *pInitialData,
  [out]  ID3D10Buffer **ppBuffer

As always in C/C++, adding an & simply returns the address of the variable. In this case, the address of the pointer.

share|improve this answer

The & is also used as a reference operator. It returns the address of the variable it's referencing too. If you had a function that took the pointer directly as a parameter, then the function will be working directly with the pointer (useful for pointer arithmetic).

Pointer pointers to resources are quite common in the D3D APIs. You usually don't want to access them directly as it's not of any benefit.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.