The last bit of code prints out the value of a pointer using two different methods, as follows:
printf( "\nPointer Output\n" );
printf( " %%p [%p] pointer\n" , &smallInt );
printf( " %%#lx [%#lx] using hex\n\n" , (unsigned long)&smallInt );
The first method uses the p type conversion. Notice that no casting is required. The second method uses the #lx specifier; this must be specified as a long hex value to get the full 64-bit pointer value and not a 32-bit one. Notice the address of smallInt must be cast to an unsigned long variable or a compilation error will result. In this instance, we are coercing the &smallIntpointer type to match the integer type specified by%#lx. Both printed values of &smallIntshould match. Theptype conversion is certainly simpler and safer.
Enter these code snippets into unsignedInt.c. Compile and run the program. You should see something similar to the following...