Advertisement
cd62131

cast exercise

Dec 3rd, 2018
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #define ARRAY_SIZE (5)
  3. int main(void) {
  4.   int i;
  5.   char array_char[ARRAY_SIZE] = {'a', 'b', 'c', 'd', 'e'};
  6.   int array_int[ARRAY_SIZE] = {1, 2, 3, 4, 5};
  7.   void *pointer_void;
  8.   pointer_void = (void *)array_int;
  9.   for (i = 0; i < ARRAY_SIZE; i++) {
  10.     printf("pointer_void は %p を指しており,値は '%d' です.\n", pointer_void,
  11.            *(int *)pointer_void);
  12.     pointer_void = (int *)pointer_void + 1;
  13.   }
  14.   pointer_void = (void *)array_char;
  15.   for (i = 0; i < ARRAY_SIZE; i++) {
  16.     printf("pointer_void は %p を指しており,値は '%c' です.\n", pointer_void,
  17.            *(char *)pointer_void);
  18.     pointer_void = (char *)pointer_void + 1;
  19.   }
  20.   return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement