Chapter 8

 < Day Day Up > 



Chapter 7

  1. What is an object? What is the difference between an object and the identifier name used to reference the object?

    An object is a region of memory. The identifier name simply points to the object, or rather, the object is accessed via the identifier name.

  2. Describe in general terms how computer memory is typically organized.

    Computer memory systems are typically byte addressable and word aligned.

  3. What operator do you use to determine an object's memory address? Give an example of its use.

    The & operator. To get the address of an object, append the & operator to the object's identifier like so:

    &objectName

  4. What is a pointer?

    A pointer is a variable that can contain a memory address.

  5. What character do you use to declare a pointer? Give several examples of its use.

    Use the * operator. For example:

    int* i = new int(3); //declares a new int pointer and sets its value to 3

    ObjectName* objptr; //declares a new ObjectName pointer

  6. What operator do you use to access an object via a pointer? Give an example of its use.

    To access an object via a pointer you have to dereference the pointer. Use the * operator to dereference pointers. For example:

    *i = 4; //set the value of the integer object pointed to by i to 4

  7. What character is used to declare a reference?

    The & operator.

  8. What are the primary differences between a pointer and a reference?

    A pointer is a variable and can be changed. A reference cannot be changed once initialized.

  9. How do you access the object referred to by a reference? How is this different from accessing an object via a pointer?

    You use references just like regular identifier names. A reference is like a nickname for an object.

  10. (T/F) A pointer is a variable.

    TRUE



 < 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