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 9SA

Explanation of Solution

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

#include <iostream> 

using namespace std; 

int main()  

{  

    //declare variables dec1, dec2 and initialize

    double dec1 = 2.5;

    double dec2 = 3.8;

    //declare double pointers p and q

    double *p, *q;

    //assign the address of variable dec1 to p

    p = &dec1;

    //assign the value of dec2 - dec1 to the memory

    //location pointed to by p which is dec1

    //so dec1 now holds the value (3.8-2.5 =) 1.3

    *p = dec2 - dec1;

    //q is assigned the value of p so both the pointers

    //now point to variable dec1

    q = p;

    //content of the memory location pointed to by q

    //is assigned 10.00 so dec1 holds the value 10.0

    *q = 10.0;

    //the contents of the memory location pointed to by p

    //i.e dec1 is assigned the value of the RHS expression

    //RHS = 2 &*#x00A0;10 + 10...

Blurred answer
Students have asked these similar questions
In C++ fill in the blanks
Write c++ code(using nested while loop only)
In C++ language only !!
Knowledge Booster
Background pattern image
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