Skip to main content
Post Migrated Here from stackoverflow.com (revisions)
Post Made Community Wiki
Source Link

You can, but compiler optimizations are free to create invalid results (gcc and msvc won't, but clang will).

char* myArray = malloc(100) - 1; /* now myArray[1] is the first element, and myArray[100] is the last. */ free(myArray + 1); 

But, as other people have mentioned, don't do this. Un-learn your bad habits of starting at 1.

Another solution: Just ignore the first element of the array.