PRO
Elijah
asked

Expert
Abhay Jajodia answered
Hi Elijah,
Yes, exactly. In C++, when you declare multiple variables on the same line, they all have to be the same type. So if you're declaring int age, id;, both variables are integers.
This is mostly for convenience and cleaner code when you're working with variables of the same type. But if the variables are different types — like an int for age and a string for name — then you'd declare them separately:
int age = 24;
string name = "John";
So grouping variables on one line only works when their data type is the same.
If you have more questions, I’m here to help.
C++
This question was asked as part of the Learn C++ Basics course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer