Re:Why I haven't given up on C++
by dancsi on Monday February 15, 2016 @06:41AM
(#11102781)
Your second point depends, in fact, on whether buffer was allocated statically.
[ Parent
| on HN ]
Er, no.
#include <stdio.h>
static char buffer[80];
static char *bufferp=buffer;
int main(int argc, char *argv[] )
{
char localbuffer[80];
char *localbufferp=localbuffer;
printf("buffer: %ld\n",sizeof buffer);
printf("bufferp: %ld\n",sizeof bufferp);
printf("localbuffer: %ld\n",sizeof localbuffer);
printf("localbufferp: %ld\n",sizeof localbufferp);
}
Output: marcel@sarek[tmp]./a.out
buffer: 80
bufferp: 8
localbuffer: 80
localbufferp: 8
As you can see, it depends entirely on whether you give sizeof the array or the pointer.