Skill Building Exercises

 < Day Day Up > 



  1. Research Memory Organization: Research the architecture of your computer. Write a brief description of how the hardware and operating system work together to manage memory resources.

  2. Determine Object Address Using & Operator: Write a program that creates three variables with different data types and assign each a value. Use the & operator to determine the address of each variable. Print the value of each variable and its memory address to the screen.

  3. Dissemble Code: Disassemble the program you wrote in exercise 2 above and study the output. Examine the listing to determine how and where the variables are being stored in memory.

  4. Declare and Initialize Pointers: Write a program that declares a char, int, float, and double variable. Initialize each variable to a value of your choice. Next, declare four pointers, one for each data type char, int, float, and double. Assign the address of each object to the proper corresponding pointer variable using the & operator. Print the value of each object to the screen using the variable name, and the dereferenced pointer. (Remember to use the * operator to dereference each pointer.)

  5. Modify Objects Via Pointer: Using the code you wrote in exercise 4, change the value of each object via the pointer. Print the new values to the screen.

  6. Dynamically Create and Destroy Objects: Write a program that declares four pointer variables, one for each data type char, int, float, and double. Use the new operator to dynamically create an object of each type and assign its address to the corresponding pointer variable. Use the pointer to initialize each object and print their values to the screen. Use the delete operator to release the dynamically allocated memory back to the operating system.

  7. References: Write a program and declare and initialize three variables of any type and value your choose. Declare three references of the required type and initialize them using the three variables previously declared. Access and modify each of the three objects via the references. Print the object values to the screen using the references.

  8. Thinking: Describe in your own words the differences between pointers and references.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net