2018-09-14 Pointers

posted Sep 14, 2018, 10:14 AM by Konstantinovich Samuel   [ updated Sep 14, 2018, 10:52 AM ]
Printf Quick reference:
http://www.pixelbeat.org/programming/gcc/format_specs.html
(Because I hate the man pages too)

Homework: Get to the pointer!
Make a repo named: MKS65C-pointy

Write a program pointy.c 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).
        

Comments