The decimal number 1113355579999 is too large to be accommodated by a 32-bit integer, which is a common size for type long int
, and in fact is the size of long long int
in your MSVC environment. On a C implementation that provides 32-bit long int
s, that constant has type long long int
.
You can pass a long long int
to a parameter of type long int
, but if the value is too large for long int
then the resulting behavior is implementation-defined. Possibly the least-significant 32 bits are retained, which, in the case of your particular number, would result in the number 959050335 (look familiar?). To pass the argument into the function without loss of fidelity, the function parameter must have a type that can accommodate the argument. On a conforming C implementation, long long int
will suffice.
Having received the argument correctly, the function must also present it correctly to printf()
, else the behavior is undefined. The formatting directive for a long long int
expressed in decimal is %lld
.
Putting that together, you appear to want this:
int FindCommonDigit(long long int n1, long long int n2) {
printf("%lld\n", n1);
return /* ... something ... */;
}
You do need the function to return an int
, else the behavior is again undefined.
Additionally, as @pmg observed in comments, a prototype for that function must be in scope at the point where it is called. That would be this ...
int FindCommonDigit(long long int n1, long long int n2);
... near the top of the source file in which the function is used (i.e. main.c
). You can put that directly into the file if you like, but you should consider instead putting the prototype into a header file and #include
ing that. The latter is particularly useful if the function will be used in multiple source files.