gcc says: In function 'main':
error: syntax error before "int"
error: syntax error before "char"
i am following a book and the books doesnt really explain: char_pointer = (*char) ((int*)char_pointer + 1);Code:#include <stdio.h> int main(){ int i; char char_array[5] = {'a', 'b', 'c', 'd', 'e'}; int int_array[5] = {1,2,3,4,5}; char *char_pointer; int *int_pointer; char_pointer = (char*) int_array; /*typecast into the pointers data type*/ int_pointer = (int*) char_array; for(i=0; i < 5; i++){ printf("[integer pointer] points to %p, which is contains the char '%c'\n", int_pointer, *int_pointer); int_pointer = (*int) ((char*)int_pointer + 1); } for(i=0; i < 5; i++){ printf("[char pointer] points to %p, which contains the int %d\n", char_pointer, *char_pointer); char_pointer = (*char) ((int*)char_pointer + 1); } }
i would like to know what that piece of code is doing. also because ive already typecast in the beginning. so i dont see why its repeated.
EDIT: I also dont understand the argument. isnt typecasting supposed to have this format: (typecast_data) variable ? so wouldnt it be just ((int*) char_pointer+1); ?



LinkBack URL
About LinkBacks



