0% found this document useful (0 votes)
13 views

C++ 06 Declare Multiple Variables

This document discusses declaring multiple variables in C++. It explains that you can declare multiple variables of the same type in a comma-separated list. It also explains that you can assign the same value to multiple variables in one line by using the assignment operator.

Uploaded by

erik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

C++ 06 Declare Multiple Variables

This document discusses declaring multiple variables in C++. It explains that you can declare multiple variables of the same type in a comma-separated list. It also explains that you can assign the same value to multiple variables in one line by using the assignment operator.

Uploaded by

erik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1/28/24, 9:45 PM C++ Declare Multiple Variables

 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

C++ Declare Multiple Variables


❮ Previous Next ❯

Declare Many Variables


To declare more than one variable of the same type, use a comma-separated list:

Example
int x = 5, y = 6, z = 50;
cout << x + y + z;

Try it Yourself »

One Value to Multiple Variables


You can also assign the same value to multiple variables in one line:

Example

int x, y, z;
x = y = z = 50;

https://www.w3schools.com/cpp/cpp_variables_multiple.asp 1/5
1/28/24, 9:45 PM C++ Declare Multiple Variables

cout << x + y + z;
 Tutorials  Exercises  Services   Sign Up Log in

 Try itCSS
HTML YourselfJAVASCRIPT
» SQL PYTHON JAVA PHP HOW TO W3.CSS C

❮ Previous Log in to track progress Next ❯

ADVERTISEMENT

Ads by

Stop seeing this


ad

Why this ad?

https://www.w3schools.com/cpp/cpp_variables_multiple.asp 2/5
1/28/24, 9:45 PM C++ Declare Multiple Variables

 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

COLOR PICKER



ADVERTISEMENT ADVERTISEMENT

https://www.w3schools.com/cpp/cpp_variables_multiple.asp 3/5
1/28/24, 9:45 PM C++ Declare Multiple Variables

 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS
 SPACES
JAVASCRIPT SQL
UPGRADE
PYTHON JAVA
AD-FREE
PHP HOW TO W3.CSS C

NEWSLETTER GET CERTIFIED REPORT ERROR

Top Tutorials Top References


HTML Tutorial HTML Reference
CSS Tutorial CSS Reference
JavaScript Tutorial JavaScript Reference
How To Tutorial SQL Reference
SQL Tutorial Python Reference
Python Tutorial W3.CSS Reference
W3.CSS Tutorial Bootstrap Reference
Bootstrap Tutorial PHP Reference
PHP Tutorial HTML Colors
Java Tutorial Java Reference
C++ Tutorial Angular Reference
jQuery Tutorial jQuery Reference

Top Examples Get Certified


HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate

    FORUM ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to
improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of
use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by

https://www.w3schools.com/cpp/cpp_variables_multiple.asp 4/5
1/28/24, 9:45 PM C++ Declare Multiple Variables
W3.CSS.

 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

https://www.w3schools.com/cpp/cpp_variables_multiple.asp 5/5

You might also like