Memory allocation (calloc, malloc) for unsigned int-Collection of common programming errors
calloc returns void*
so you should use it like
unsigned int* part1 = calloc (1,sizeof(*part1));
then assign it like
*part1 = 42;
If you have allocated space for several elements
part1[0] = 42; // valid indices are [0..nmemb-1]
may be clearer.
Note that you also have to free
this memory later
free(part1);
Alternatively, if you only need a single element, just declare it on the stack
unsigned int part1 = 42;
Regarding why casting a point to unsigned long
doesn’t generate a warning, sizeof(void*)==sizeof(unsigned long)
on your platform. Your code would not be portable if you relied on this. More importantly, if you use a pointer to store a single integer, you’d leak your newly allocated memory and be unable to ever store more than one element of an array.