dev-resources.site
for different kinds of informations.
Day 4: C++ language | Variables | Datatypes | Part-2
Published at
1/4/2025
Categories
Author
Mehfila A Parkkulthil
Categories
1 categories in total
open
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 ;
}
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;
}
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;
}
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.
Previous Blog
Articles
12 articles in total
Whats your TECH stack ?? How did you get into that??
read article
Day 7 : C++ language | Comparison Operators
read article
Day 6: C++ Language | Assignment operators
read article
Day 5: C++ language | Arithmetic Operators
read article
Day 4: C++ language | Variables | Datatypes | Part-2
currently reading
Its inbox is a gem💎
read article
A promising introduction for both coding novices and experienced developers!😊👩🎓
read article
Day 3: C++ language | Variables | Datatypes | Part-1
read article
Day 2: C++ language - Output
read article
Day 1 : C++ language | Introduction
read article
Day 1 : Introduction of DSA
read article
You need to learn DSA , to earn.
read article
Featured ones: