C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
Expert Solution & Answer
Book Icon
Chapter 12, Problem 12SA

Explanation of Solution

The program execution is explained in the in-lined comments:

#include <iostream> 

#include <iomanip>

using namespace std; 

int main()  

{  

    //declare pointer variables and allocate memory

    int *myPtr = new int;

    int *yourPtr = new int;

    //assign value to the memory location pointed to by myPtr

    *myPtr = 10;

    //assign value to memory location pointed to by myPtr

    //using an arithmetic expression

    //RHS expression = 2 &*#x00A0;10 + 3 = 23

    *yourPtr = 2 &*#x00A0;*myPtr + 3;

    //print statement using arithmetic expression

    //value held in memory location myPtr is 10

    //the second expression = (23 - 10 + 5) = 18

    cout << *myPtr << " " << (*yourPtr - *myPtr + 5) << endl;

    //pointer myPtr assigned the pointer yourPtr so

    //now myPtr refers to the memory location holding

    //the value 23

    myPtr = yourPtr;

  ;&#...

Blurred answer
Students have asked these similar questions
Look at the following C++ code and comment each line about how it works with pointer. int i = 33; double d = 12.88; int * iPtr = &i;      double * dPtr = &d; //   iPtr = &d;   //   dPtr = &i;   //   iPtr = i;    //     int j = 99; iPtr = &j;  //
This assignment is not graded, I just need to understand how to do it. Please help, thank you! Language: C++ Given: Main.cpp #include #include "Shape.h" using namespace std; void main() {   /////// Untouchable Block #1 //////////   Shape* shape;   /////// End of Untouchable Block #1 //////////    /////// Untouchable Block #2 //////////   if (shape == nullptr) {       cout << "What shape is this?! Good bye!";       return;   }    cout << "The perimeter of your " << shape->getShapeName() << ": " <<       shape->getPerimeter() << endl;   cout << "The area of your " << shape->getShapeName() << ": " <<       shape->getArea() << endl;   /////// End of Untouchable Block #2 //////////} Shape.cpp string Shape::getShapeName() {   switch (mShapeType)    {   case ShapeType::CIRCLE:       return "circle";   case ShapeType::SQUARE:       return "square";   case ShapeType::RECTANGLE:       return "rectangle";   case…
Code using c++ 2. Solving a Person's Loneliness by CodeChum Admin It's been 1,245 years and our sole Person is getting lonelier each day. This Person definitely needs a partner!   Thus, we need to update our Person's design to have a gender as well and there shall be male and female!     Instructions: In the code editor, you are provided with the definition of a struct Person. This struct needs an integer value for its age. Furthermore, you are provided with a displayPerson() function which accepts a struct Person as its parameter. Your task is to first update the struct Person so that it can have a gender as well. For this program, we shall represent a gender with a single character: 'M' for male and 'F' for female. Then, create a Person, take in an integer user input and a character user input, and then set them as the Person's age and gender respectively. Finally, call the displayPerson() function and pass that Person you created. Input 1. The age of the Person 2.…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education