C++ Variable Initialization Question

Question

Write a program that defines three variables inside the main function.

The variables are of char, int, and type double.

The names of the variables are arbitrary.

The initializers are arbitrary.

The initialization is performed using the initializer list.

Print the values afterward.




#include <iostream> 

int main() 
{ 
    char mychar{ 'a' }; 
    int myint{ 123 }; 
    double mydouble{ 456.78 }; 
    std::cout << "The value of a char variable is: " << mychar << '\n'; 
    std::cout << "The value of an int variable is: " << myint << '\n'; 
    std::cout << "The value of a double variable is: " << mydouble << '\n'; 
} 



PreviousNext

Related