Data types and variables | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Data types and variables

If a variable is defined to be a particular data type, can the same variable be used for a different data type in the same program?

17th Apr 2020, 9:08 AM
Sai Santhosh
Sai Santhosh - avatar
1 Answer
+ 1
That is not possible, C++ is a statically typed language, where the data types are fixed at compile time. However, unions and variants provide a way for a variable to be able to hold values of different types. https://en.cppreference.com/w/cpp/language/union https://en.cppreference.com/w/cpp/utility/variant
17th Apr 2020, 9:30 AM
Shadow
Shadow - avatar