fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define IsNull(expr) ((expr) == NULL)
  4.  
  5. #define CALLOC(var, size,type) ; \
  6. if (IsNull((var) = ((type *)calloc((size),sizeof(type))))) { \
  7. perror(0); return EXIT_FAILURE; \
  8. };
  9.  
  10. inline void printArr(int *A, int f, int e) {
  11. int i;
  12. for (i = f; i < e; i++) {
  13. printf("A[%d] = %d\n", i, A[i]);
  14. }
  15. }
  16.  
  17. int main(void) {
  18. // your code goes here
  19. int *a, *b, *p;
  20. int i;
  21.  
  22. CALLOC(a,10,int);
  23. CALLOC(b,10,int);
  24.  
  25. for (i = 0; i < 6; i++) {
  26. a[i] = (i + 1) * (i + 1);
  27. }
  28.  
  29. printf("a:0x%x\n", a);
  30. printf("b:0x%x\n", b);
  31.  
  32. printArr(a, 0, 8);
  33.  
  34. p = (int *)realloc(a, 200);
  35.  
  36. if (IsNull(p)) {
  37. perror(0);
  38. return EXIT_FAILURE;
  39. } else {
  40. a = p;
  41. }
  42.  
  43. printf("a:0x%x\n", a);
  44. printArr(a, 0, 8);
  45.  
  46. free(a);
  47. free(b);
  48.  
  49. return EXIT_SUCCESS;
  50. }
  51.  
Success #stdin #stdout 0s 2424KB
stdin
Standard input is empty
stdout
a:0x82e4008
b:0x82e4038
A[0] = 1
A[1] = 4
A[2] = 9
A[3] = 16
A[4] = 25
A[5] = 36
A[6] = 0
A[7] = 0
a:0x82e4068
A[0] = 1
A[1] = 4
A[2] = 9
A[3] = 16
A[4] = 25
A[5] = 36
A[6] = 0
A[7] = 0