Work 02: Get to the point.

posted Sep 14, 2018, 10:04 AM by JonAlf Dyrland-Weaver
This is going to seem strange to many of you, but follow along.

Write a program that:
  1. Declares and initializes an unsigned int to some value > 2.1 billion.
  2. Declare a char * that points to the address of your unsigned int.
    • Yes, I really do mean char *
  3. Print out your int in hex. 
    • The formatting character for a hexadecimal int is: %x
  4. Use your pointer to print out each individual byte of your int.
    • The formatting character for a single byte in hex is %hhx, that is half of half of an integer.
  5. Using your pointer, modify the individual bytes of your int and print out the resulting value in hex and decimal after each modification.
    1. Increment each byte by 1
    2. Increment each byte by 16
  6. Feel free to try other things
NOTE: You do not need anything more than the basic pointer operations and the printf formatting characters to do this assignment. Stay away from confusing posts on stack overflow (and the like).

GitHub clone url: