arrays - what does the following c++ code do -
arrays - what does the following c++ code do -
i know naive question, not able understand next code does.
#include <malloc.h> #define maxrow 3 #define maxcol 4 int main(){ int (*p)[maxcol]; p = (int (*)[maxcol])malloc(maxrow*sizeof(*p)); }
please provide finish explanation including type , size of p.
it learning purpose. not using code in real application.
as far can tell, it's gibberish. meant (int(*)[maxcol])
.
in c means programmer wrote doesn't know how void pointer typecasts work.
in c++ means allocating array of arrays. p array pointer, *p array of size maxcol, , allocate maxrow such arrays. result "mangled" 2d array. avantage of using rather obscure syntax 2d array has every cell in adjacent memory, wouldn't accomplish more commonly seen pointer-to-pointer dynamic 2d array.
c++ arrays malloc
Comments
Post a Comment