C++ Automatic Type Deduction Question

Introduction

Write a program that automatically deduces the type for char, int, and double objects based on the initializer used.

Print out the values afterward.

You can use the following code structure.

#include <iostream> 

int main() 
{ 
    //your code here
} 


#include <iostream> 

int main() 
{ 
    auto c = 'a'; 
    auto x = 123; 
    auto d = 3.14; 

     std::cout << "The type of c is deduced as char, the value is: "   
     << c << '\n'; 
     std::cout << "The type of x is deduced as int, the value is: "   
     << x << '\n'; 
     std::cout << "The type of d is deduced as double, the value is: "   
     << d << '\n'; 
} 



PreviousNext

Related