C++ const Type Qualifier Question

Introduction

Write a program that defines three objects of type const int, const double and const std::string, respectively.

Define a fourth const int object and initialize it with a value of the first const int object.

Print out the values of all the variables.

You can use the following code structure.

#include <iostream> 

int main() 
{ 
    //your code here
} 



#include <iostream> 

int main() 
{ 
    const int c1 = 123; 
    const double d = 456.789; 
    const std::string s = "Hello World!"; 
    const int c2 = c1; 

    std::cout << "Constant integer c1 value: " << c1 << '\n'; 
    std::cout << "Constant double d value: " << d << '\n'; 
    std::cout << "Constant std::string s value: " << s << '\n'; 
    std::cout << "Constant integer c2 value: " << c2 << '\n'; 
} 



PreviousNext

Related