Difference between int and var in C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

16th May 2018, 6:34 AM
Rain.Carnation
Rain.Carnation - avatar
4 Answers
+ 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.
16th May 2018, 6:46 AM
Cain Eviatar
Cain Eviatar - avatar
+ 1
what about C
16th May 2018, 6:47 AM
Rain.Carnation
Rain.Carnation - avatar
+ 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 )
16th May 2018, 6:49 AM
Cain Eviatar
Cain Eviatar - avatar
+ 1
thanks 😊
16th May 2018, 6:49 AM
Rain.Carnation
Rain.Carnation - avatar