TOPIC: POINTERS 1.Create a C function main() and do the following sequence of instructions: 1. Declare two integer variables x and y. 2. Declare two pointer variables p and q. 3. Assign the following values: x=15, y=25. 4. Print the values of x and y. 5. Let the pointer p points to the address of x 6. Print the value of x and the address of x using the pointer variable p 7. Increment the value of x by 5 using the pointer variable p 8. Print the value of x (using x and p variables) 9. Let the pointer variable q points to the address of y. 10. Print the value of y and the address of y using the pointer variable q. 11. Add the value of x to the value stored in y using their pointer variables p and q. 12. Print the new values of x and y using the pointer variables p and q. 13. Let pointer p points to the address where the pointer q also points. 14. Print the address of the variable pointed to by p and q. 15. Change the value of y (let y=50) using the pointer p 16. Print the value of x and y (using their variable names) 17. Print the values pointed by p and q.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question

TOPIC: POINTERS

1.Create a C function main() and do the following sequence of instructions:

1. Declare two integer variables x and y.
2. Declare two pointer variables p and q.
3. Assign the following values: x=15, y=25.
4. Print the values of x and y.
5. Let the pointer p points to the address of x
6. Print the value of x and the address of x using the pointer variable p
7. Increment the value of x by 5 using the pointer variable p
8. Print the value of x (using x and p variables)
9. Let the pointer variable q points to the address of y.
10. Print the value of y and the address of y using the pointer variable q.
11. Add the value of x to the value stored in y using their pointer variables p and q.
12. Print the new values of x and y using the pointer variables p and q.
13. Let pointer p points to the address where the pointer q also points.
14. Print the address of the variable pointed to by p and q.
15. Change the value of y (let y=50) using the pointer p
16. Print the value of x and y (using their variable names)
17. Print the values pointed by p and q.

Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Intelligent Machines
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr