bounds.c 647 B

12345678910111213141516171819202122232425
  1. // bounds.c -- exceed the bounds of an array
  2. #include <stdio.h>
  3. #define SIZE 4
  4. int main(void)
  5. {
  6. int value1 = 44;
  7. int arr[SIZE];
  8. int value2 = 88;
  9. int i;
  10. printf("value1 = %d, value2 = %d\n", value1, value2);
  11. for (i = -1; i <= SIZE; i++)
  12. arr[i] = 2 * i + 1;
  13. for (i = -1; i < 7; i++)
  14. printf("%2d %d\n", i , arr[i]);
  15. printf("value1 = %d, value2 = %d\n", value1, value2);
  16. printf("address of arr[-1]: %p\n", &arr[-1]);
  17. printf("address of arr[4]: %p\n", &arr[4]);
  18. printf("address of value1: %p\n", &value1);
  19. printf("address of value2: %p\n", &value2);
  20. return 0;
  21. }