Reputation: 27
How many bytes were allocated by double *p[10]; ?
I am wondering between 4 bytes (= 1 pointer size) and 10 x 4 bytes (= array of 10 pointers).
Upvotes: 1
Views: 591
Reputation: 31469
If you wonder how much space p
takes, simply do:
printf("%zu", sizeof p);
If you want to know exactly what type it is, use this site https://cdecl.org/
In your case, p
is not a pointer. It's an array of pointers. If you change to double (*p)[10]
you will instead get a pointer to array.
Upvotes: 1
Reputation: 1
You have an array of ten pointers. It contains bogus values, and you should initialize it (maybe clearing it with memset
).
On your machine, ten pointers need forty bytes.
On my desktop (x86-64 running Ubuntu 20.04, using a GCC compiler) they need 80 bytes
On some microcontrollers (perhaps Arduino) a pointer could take just two bytes. In 2021 you would use some cross-compiler for these.
See this C reference and some C standard like n1570 or better.
Take inspiration from the source code of existing open source C software like GNU make.
And study the source code of some open source C compiler coded in C, like tinycc.
Upvotes: 2