Day 4: C++ language | Variables | Datatypes | Part-2

Please make sure to refer Day3: C++ language | Variables | Datatypes | Part-1

Topics to be covered

Variables
Declare multiple Variables
User Input

Variables

#include <iostream>
using namespace std;
int main(){
i…


This content originally appeared on DEV Community and was authored by Mehfila A Parkkulthil

Please make sure to refer Day3: C++ language | Variables | Datatypes | Part-1

Topics to be covered

  • Variables
  • Declare multiple Variables
  • User Input

Variables

#include <iostream>
using namespace std;
int main(){
int age = 15;
cout << "my age is:" << age << endl ;

}

Image

Image

Declare multiple variables

To declare more than one variable of the same type.

#include <iostream>
using namespace std;
int main(){

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

}

multiple variables

result

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

#include <iostream>
using namespace std;

int main(){

int x, y, z;
x = y = z = 60;
cout << x + y + z;

}

mul variables

Imagey

User input

In C++, the term "input" generally refers to the process of taking data from an external source (like the user or a file) and storing it in a variable for use in your program.

cin is a predefined variable that reads data from the keyboard with the extraction operator (>>) .

  • cout is pronounced "see-out". Used for output,and uses the insertion operator (<<)
  • cin is pronounced "see-in". Used for input, and uses the extraction operator (>>)

int z, y;
int sum;
cout << "Type a number: ";
cin >> z;
cout << "Type another number: ";
cin >> y;
sum = x + y;
cout << "Sum is: " << sum;

Here I gave two numbers 50 and 45 , it can be any according to that result varies.

Input

Input terminal

Input .v

Previous Blog


This content originally appeared on DEV Community and was authored by Mehfila A Parkkulthil


Print Share Comment Cite Upload Translate Updates
APA

Mehfila A Parkkulthil | Sciencx (2025-01-04T14:24:19+00:00) Day 4: C++ language | Variables | Datatypes | Part-2. Retrieved from https://www.scien.cx/2025/01/04/day-4-c-language-variables-datatypes-part-2/

MLA
" » Day 4: C++ language | Variables | Datatypes | Part-2." Mehfila A Parkkulthil | Sciencx - Saturday January 4, 2025, https://www.scien.cx/2025/01/04/day-4-c-language-variables-datatypes-part-2/
HARVARD
Mehfila A Parkkulthil | Sciencx Saturday January 4, 2025 » Day 4: C++ language | Variables | Datatypes | Part-2., viewed ,<https://www.scien.cx/2025/01/04/day-4-c-language-variables-datatypes-part-2/>
VANCOUVER
Mehfila A Parkkulthil | Sciencx - » Day 4: C++ language | Variables | Datatypes | Part-2. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/04/day-4-c-language-variables-datatypes-part-2/
CHICAGO
" » Day 4: C++ language | Variables | Datatypes | Part-2." Mehfila A Parkkulthil | Sciencx - Accessed . https://www.scien.cx/2025/01/04/day-4-c-language-variables-datatypes-part-2/
IEEE
" » Day 4: C++ language | Variables | Datatypes | Part-2." Mehfila A Parkkulthil | Sciencx [Online]. Available: https://www.scien.cx/2025/01/04/day-4-c-language-variables-datatypes-part-2/. [Accessed: ]
rf:citation
» Day 4: C++ language | Variables | Datatypes | Part-2 | Mehfila A Parkkulthil | Sciencx | https://www.scien.cx/2025/01/04/day-4-c-language-variables-datatypes-part-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.