the above program displays an error NUMERIC CONSTANT TOO LARGE....why is it so..? why is it not giving the output -2147483648..?Code:main() { long int a=2147483647+1; printf("%ld",a); getch(); }
the above program displays an error NUMERIC CONSTANT TOO LARGE....why is it so..? why is it not giving the output -2147483648..?Code:main() { long int a=2147483647+1; printf("%ld",a); getch(); }
I think you preprocessor is calculating the value, not the executable.
Try this instead (and set optimization options to a very low level)
Note that going over the range of valid values for an int is Undefined Behaviour.Code:#include <stdio.h> int main() { long int a = 2147483647; a += 1; printf("%ld", a); getch(); return 0; }
Because when you just write some number in your code, that number has a type normally that type is int. When you want it to be a different type then you need to let the compiler know.
How you do that is to put the appropriate suffix on the value. The suffix for long is L.
Then you only have to make sure that long is more than 32-bits on your system so that 2147483647L + 1L does not overflow. Otherwise you'd have to use either unsigned long (suffix UL), or long long (suffix LL)
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
it certainly unlikely that the program is outputting that error message when you run it. it is a compiler warning, right?