I'm new to c. Just learning. What i am trying to do is initialize a variable type of unsigned int and then store address of an char type array in it and after that I am trying to use int as a pointer and print the array using the unsigned int but I'am getting segmentation fault, I don't know why? It's printing value of memory address of char type array. But not the actual values at memory addresses. Can someone please help?
#include <stdio.h>
int main()
{
char char_arr[4] = {'a', 'b', 'c', 'd'};
int i;
unsigned int hackyPointer;
hackyPointer = (unsigned int) char_arr;
for (i = 0; i < 4; i++)
{
printf("[hacky Pointer] now points to %p which contains value %c\n",hackyPointer, *((char *) hackyPointer));
hackyPointer += sizeof(char);
}
}
%pto print an integer. The other is that your pointer size might be larger than can fit intounsigned int.