更新时间:2023-12-04 11:43:52
这个数字大于一个整数(有4个字节),它可以容纳2 ^ 31-1和一点符号。
用于电话号码的char数组通常命名为字符串。
谷歌的一些教程。 ; - )
I wrote a very small code in C which basically takes input from user, save in variable and print it out the same input given by user to screen.
But, When I entered "9879041552" it printed out really strange number. Although, some numbers are working fine, the numbers which are limited to 4 digits.
What's causing this unexpected behavior?
#include
#include
int main()
{
int mobileNumber;
printf("Enter your mobile number: ");
scanf("%d", &mobileNumber);
printf("Your mobile number is: %d", mobileNumber);
return 0;
}
What I have tried:
I am beginner to programming. I tried searching online but it doesn't give me any reason why this happened.
The number is bigger than an integer (with 4 bytes) which holds up to 2^31-1 and a bit for the sign.
Use for phone numbers a char array often named string.
Google for some tutorials. ;-)