Returning a long long value

Pulkit Sinha picture Pulkit Sinha · Jan 24, 2011 · Viewed 7.5k times · Source
#include <stdio.h>

int main(void) 
{
    long long x = test();
    printf("%lld\n", x);

    return 1;
}

long long test()
{   
    return 1111111111111111111;
} 

The output is 734294471 . If I replace the call to test() by a the number, the output is as I expect. I checked the value of x using a debugger and it wasn't set the to value returned by the function. What is going wrong?

I am using Visual Studio 2010 with the Visual C++ compiler.

Answer

Ned Batchelder picture Ned Batchelder · Jan 24, 2011

You need to declare test before you call it, otherwise C assumes it returns int.