Output 2147483647 kyu aa rha he?

//WAP to demonstrate an example of cascading cout and cin

#include<iostream.h>

#include<conio.h>

using namespace std;

int main()

{

 int num;

cout<<"Enter a number\n";

cin>>num;

cout<<"You are enterd this number : "<<num;

getch();

}

When I input digit from 1 to 9 then output of my program is 123456789 which is correct according to my program but when I input my phone number 9887370536 the output is 2147483647 which is totally different from my phone number.

Dear Learner,

Welcome to LearnVern! We are happy to serve you.

The reason you are getting this error is that you are using type ‘int’ to store your variable ‘num’ but type ‘int’ can store numbers ranging between -2147483647 and 2147483647 only. Since your phone number is greater than 2147483647, you are being displayed the maximum number that can be stored, which is 2147483647.

Please use a data type that can actually store a large number like your phone number. You can use the “long long” data type for this.

We hope our reply serves your query well.
Keep learning.


Thanks and Regards,
Siddhant
Team LearnVern.