Create a new project named lab6_1. Read the steps for each portion of this lab. Diagram the memory as outlined in the steps (don’t need to turn this part in). Then, write the code to verify your written work. Declare int variables x and y and int* pointer variables p and q.  Set x to 2, y to 8, p to the address of x, and q to the address of y.  Then print the following information: The address of x (use the address operator) and the value of x. For example, that output statement may look like:  cout << "&x = " << &x << ", x = " << x << endl; The value of p and the value of *p. The address of y (use address operator) and the value of y. The value of q and the value of *q. The address of p (not its contents, don’t dereference). The address of q (not its contents, don't dereference). How are the addresses of x, y, p, and q related? List them out and find the distances between each address. You can include these answers in your program as a block comment. Comment out the previous code. Now, declare int variables x, y, temp and int* pointer variables p, q, temp_ptr.  Set x, y, temp to three distinct values. Set p, q, temp_ptr to the addresses of x, y, temp respectively. Print, with labels, the values of x, y, temp, p, q, temp_ptr, *p, *q, *temp_ptr. Print the message: Swapping values. Then, use the following swap code: temp = x; x = y; y = temp; Print with labels the values of x, y, temp, p, q, temp_ptr, *p, *q, *temp_ptr. What was the effect of the swap code? Which values changed? You can include these answers in your program as a block comment. Comment out the previous code. Declare int variables x, y, temp and int* pointer variables p, q, temp_ptr.  Set x, y, temp to three distinct values.  Set p, q, temp_ptr to the addresses of x, y, temp respectively. Print, with labels, the values of x, y, temp, p, q, temp_ptr, *p, *q, *temp_ptr. Print the message: Swapping pointers. Then, use the following swap code:  temp_ptr = p; p = q; q = temp_ptr; Print with labels the values of x, y, temp, p, q, temp_ptr, *p, *q, *temp_ptr. What was the effect of the swap code? Which values changed? You can include these answers in your program as a block comment.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  1. Create a new project named lab6_1. Read the steps for each portion of this lab. Diagram the memory as outlined in the steps (don’t need to turn this part in). Then, write the code to verify your written work.
    1. Declare int variables x and y and int* pointer variables p and q.  Set x to 2, y to 8, p to the address of x, and q to the address of y.  Then print the following information:

      1. The address of x (use the address operator) and the value of x.

        For example, that output statement may look like: 

        cout << "&x = " << &x << ", x = " << x << endl;
      2. The value of p and the value of *p.

      3. The address of y (use address operator) and the value of y.

      4. The value of q and the value of *q.

      5. The address of p (not its contents, don’t dereference).

      6. The address of q (not its contents, don't dereference).
      7. How are the addresses of x, y, p, and q related? List them out and find the distances between each address. You can include these answers in your program as a block comment.

    2. Comment out the previous code. Now, declare int variables x, y, temp and int* pointer variables p, q, temp_ptr.  Set x, y, temp to three distinct values. Set p, q, temp_ptr to the addresses of x, y, temp respectively.

      1. Print, with labels, the values of x, y, temp, p, q, temp_ptr, *p, *q, *temp_ptr.
      2. Print the message: Swapping values.

      3. Then, use the following swap code:
        1. temp = x;
        2. x = y;
        3. y = temp;
      4. Print with labels the values of x, y, temp, p, q, temp_ptr, *p, *q, *temp_ptr.
      5. What was the effect of the swap code? Which values changed? You can include these answers in your program as a block comment.
    3. Comment out the previous code. Declare int variables x, y, temp and int* pointer variables p, q, temp_ptr.  Set x, y, temp to three distinct values.  Set p, q, temp_ptr to the addresses of x, y, temp respectively.
      1. Print, with labels, the values of x, y, temp, p, q, temp_ptr, *p, *q, *temp_ptr.
      2. Print the message: Swapping pointers.

      3. Then, use the following swap code: 

        1. temp_ptr = p;
        2. p = q;
        3. q = temp_ptr;
      4. Print with labels the values of x, y, temp, p, q, temp_ptr, *p, *q, *temp_ptr.

      5. What was the effect of the swap code? Which values changed? You can include these answers in your program as a block comment.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Software Development Approaches
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education