How to Read and Print an Integer value in C++

C++Server Side ProgrammingProgramming

Here we will see how to read integer from user and display in C++. To take input we will use the cin operator, and to display we will use cout operator. The syntax will be like −

Input −

int x;
cin >> x;

Output −

int x = 110;
cout << x;

Example

 Live Demo

#include<iostream>
using namespace std;
int main(int argc, char const *argv[]) {
   int x;
   int y = 50;
   cout << "Enter some value: ";
   cin >> x;
   cout << "The given value is: " << x << endl;
   cout << "The value of y is: " << y;
}

Output

Enter some value: 100
The given value is: 100
The value of y is: 50
raja
Published on 03-Jan-2020 15:18:49
Advertisements