DEV Community

Mehfila A Parkkulthil
Mehfila A Parkkulthil

Posted on • Edited on

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(){
int age = 15;
cout << "my age is:" << age << endl ;

}
Enter fullscreen mode Exit fullscreen mode

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;

}
Enter fullscreen mode Exit fullscreen mode

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;

}

Enter fullscreen mode Exit fullscreen mode

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

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →