0
Difference between int and var in C++?
int and var both define value holders such as x However, do they both mean the same thing? Or does int define type and var intoduces variable?
4 Respuestas
+ 1
C++ doesn't have var.
int holds numbers that doesn't have floating point.
var detect what type you assigend to it.
var x = 64; ( int )
var y = 52.6; ( double )
similar to ( in C++ )
auto x = 64;
auto y = 52.6;
the closest you can get to var in C++ is to use auto and std::variant or std::any from C++17.
+ 1
what about C
+ 1
tbh I'm not sure if C has auto or not. but it surely doesn't have var.
var is known well at most scripting languages. ( js, lua, python, etc )
+ 1
thanks 😊