Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-std=c99 -Wall -Wextra -Wpedantic -Wshadow
- #include <stdio.h>
- #include <stdlib.h>
- int main (int argc, char **argv){
- //it is illegal to refer to objects that are not within the array bounds
- int arr[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21};
- int* tmp;
- tmp = arr;
- tmp-=10;
- printf("%d\n",tmp[10]);
- tmp+=21;
- printf("%d\n",tmp[0]);
- printf("%d\n\n",tmp[-1]);
- //http://c-faq.com/aryptr/non0based.html
- //int realarray[10];
- int realarray[10]={1,2,3,4,5,6,7,8,9,0};
- int *array = &realarray[-1];
- printf("%p\n",(void*)realarray);
- printf("%p\n",(void*)array);
- printf("%d\n",array[1]);
- return 0;
- }
- /*
- output:
- 1
- 12
- 11
- 0x7fff69ae6830
- 0x7fff69ae682c
- 1
- */
Advertisement
Add Comment
Please, Sign In to add comment