C++ Reference Type Question

Introduction

Write a program that defines an object of type double called mydouble.

Define an object of reference type called myreference and initialize it with mydouble.

Change the value of myreference.

Print the object value using both the reference and the original variable.

Change the value of mydouble.

Print the value of both objects.

You can use the following code structure.

#include <iostream> 

int main() 
{ 
    //your code here
} 


#include <iostream> 

int main() 
{ 
    double mydouble = 3.14; 
    double& myreference = mydouble; 

    myreference = 6.28; 
    std::cout << "The values are: " 
              << mydouble 
              << " and " 
              << myreference << '\n'; 

    mydouble = 9.45; 
    std::cout << "The values are: " 
              << mydouble 
              << " and " 
              << myreference << '\n'; 
} 



PreviousNext

Related