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



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
Updated on: 2020-01-03T10:50:31+05:30

559 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements