0
Why does this code not show this number?
#include<iostream> using namespace std; int main () { int myPhone = 2^12; cout << myPhone; return 0; }
12 odpowiedzi
+ 9
Thokgamo Shadreck which number you wrote is belong to some other user and it can be misuse so I edited with that so please be careful in typing phone number ranges.
+ 5
What exactly do you want to do? 2 ^ 12 yields 14, but in case you meant to raise 2 by 14 `pow(2, 14)` then you'll get 4096. Both these numbers are within the safe range of `int`. I think the problem isn't because it was out of range value. Can you explain further of your intention?
+ 4
Maximum value you can assign to a integer in c++ is 2147483647.
The phone number exceeds the limitation.
As you are not going to do mathematical operations for phone number, it's better to define it a String.
+ 2
Alright, a minor misunderstanding, I get it now. Thanks for clarification 👍
+ 2
Syed Kumail Hussain Sherazi a moderator changed it to that, because he thought it could possibly be someones real phonenumber. The original value looked like a phonenumber.
+ 1
Because it might have too big value to be an int.
+ 1
You might change int heading to long, or long long
+ 1
Thanks a lot guys!
+ 1
I wanted to display a number so I edited the code from the tutorial and named it "int myPhone" instead of "int a" and picked a random 10 digit number. I think the admins thought it was my real number and changed it to "2^12" and added those comments in the asterix. It wasnt a working phone number (that I know of) but sorry for the confusion guys.
+ 1
The issue isn't limit. What ^ does is actually bitwise XOR operation. So binary of 2 = 0010, and binary of 12 = 1100, if we do bitwise XOR the answer is: 1110 (which is 14 in denary). You might want to look into std::pow(). A lot of scripting languages use ^ as power operator, C++ doesn't.
0
Thanks
0
Oh lol. My bad.