mallocbuff is not an array, it is a pointer. It is stored completely separately from where malloc stands out.
This will produce the expected results (and as needed):
int main(){ char buf[1]; printf("&buf == %p\n", &buf); printf(" buf == %p\n", buf); // 'buf' implicitly converted to pointer printf("&buf[0] == %p\n", &buf[0]); char* mbuf = buf; printf(" mbuf == %p\n", mbuf); printf("&mbuf[0] == %p\n", &mbuf[0]); printf("\n&mbuf(%p) != &buf(%p)\n", &mbuf, &buf); return 0; }
Conclusion:
&buf == 0x7fff5b200947 buf == 0x7fff5b200947 &buf[0] == 0x7fff5b200947 mbuf == 0x7fff5b200947 &mbuf[0] == 0x7fff5b200947 &mbuf(0x7fff5b200948) != &buf(0x7fff5b200947)
Roger Pate
source share