Declaring Multiple Variables in C++
You can declare multiple variables of the same data type in a single statement by separating them with commas.
Key Topics
Syntax
data_type variable1, variable2, variable3;
Explanation: Declare multiple variables of the same type in one line to make your code more concise.
Examples
Example: Declaring Multiple Integers
int tamil, karthickAG, rudra;
tamil = 25;
karthickAG = 30;
rudra = 28;
Code Explanation: Variables tamil
, karthickAG
, and rudra
are declared as integers and assigned values representing their ages.
Key Takeaways:
- Declaring multiple variables in one line keeps the code organized.
- Ensure variable names are unique within their scope.