Go Back   PACEDev Forums > Blogs > Chris
Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read

Software Programming musings
Old

C: sizeof(array-1)

Posted 5th December 2007 at 11:44 AM by Chris
Wonder what happens when you try to take sizeof on a fixed length array with an offset? Me too!

Quote:
int foo[12];
printf("sizeof(foo): %d\n", sizeof(foo));
printf("sizeof(foo-1): %d\n", sizeof(foo-1));
Returns:
Quote:
sizeof(foo): 48
sizeof(foo-1): 4
Peculiar!

When we try:
Quote:
printf("&foo: %p\n", &foo);
printf("&(foo-1): %p\n", &(foo-1));
...
Chris's Avatar
Overlord
Posted in Software
Comments 0 Chris is offline

All times are GMT. The time now is 03:00 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.