1

I am reading a c++ code and came across this line:

    mem_cMemRow ** ppMemory = (mem_cMemRow **)malloc(//size of some structs);

It seems to me that ** reserves some amount or portions of the memory but my search did not yield any good results. I appreciate any deeper and more detailed explanations on this.

Mohamed El-Nakeep
  • 6,580
  • 4
  • 35
  • 39
AleX_
  • 508
  • 1
  • 6
  • 20
  • 3
    it's a pointer to a pointer – Ken Apr 01 '13 at 18:16
  • 1
    It is a pointer to a pointer. Read up on double pointers. A starter here: http://www.eskimo.com/~scs/cclass/int/sx8.html – Vaibhav Desai Apr 01 '13 at 18:17
  • I am sure this blog will help you to understand , what is pointer to pointer with example http://bytebeats.com/2011/08/08/pointer-to-pointer/ – abidkhan303 Apr 01 '13 at 18:21
  • duplicate: [What is ** in C++?](http://stackoverflow.com/q/644981/995714), [what does ** mean in C](http://stackoverflow.com/q/2893129/995714), [What is double star](http://stackoverflow.com/q/604099/995714). And [don't cast the result of `malloc` in C](http://stackoverflow.com/q/605845/995714) – phuclv May 03 '17 at 02:55

3 Answers3

4
 mem_cMemRow ** ppMemory = (mem_cMemRow **)malloc(//size of some structs)

is trying to allocate memory for ppMemry, which is a pointer to pointer type of mem_cMemRow objects. It (ppMemory) is a 2D dynamic array.

taocp
  • 23,276
  • 10
  • 49
  • 62
2

Its a pointer to a pointer. Essentially you are creating an array of pointers to a given struct. Most likely the malloc is the sizeof a struct pointer times by some number.

Goz
  • 61,365
  • 24
  • 124
  • 204
1

One star means a pointer. Two stars mean a pointer to a pointer. So, ppMemory is a pointer to a pointer to a mem_cMemRow.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180