If you are trying to reinterpret the memory behind the int array as an array of bytes, and only then:
int ints[500];
char *bytes = (char *) ints;
You cannot do this without resorting to pointer casting, as declaring a []
array implies allocation on stack, and cannot be used for reinterpretation of existing memory.
Obviously, you need to know what you are doing. For each int
there will be (typically, depending on platform etc.) 4 char
s, so your new array would have 500*4
elements. Check out what the output of:
printf("char size: %d, int size: %d", sizeof(char), sizeof(int));
tells you to make sure.
If you are trying to interpret each int
as a char
, i.e. to get the same number of char
s, as there were int
s, then you cannot do this without a loop and manual conversion (to a new memory locaton, normally).