I am learning C programming language, I have just started learning arrays with pointers. I have problem in this question, I hope the that output must be
int main(){
int arr[] = {1,2,3,4,5};
char *ptr = (char *) arr;
printf("%d",*(ptr+4));
return 0;
}
Each case of arr has sizeof(int) size (which may be 4 on your implementation).
Since ptr is a pointer to char, pointer arithmetic makes ptr + 4 points 4 bytes after &arr[0], which may be &arr[1].
In memory, it looks like something like:
Address | 0 1 2 3 | 4 5 6 7 | ...
Value | arr[0] | arr[1] | ...