i have declared a int variable i.
but my program is not running if user enters a value of i more than 32766.
i have turbo c/c++ compiler.
please help.
Printable View
i have declared a int variable i.
but my program is not running if user enters a value of i more than 32766.
i have turbo c/c++ compiler.
please help.
Change to a compiler that has a greater range for int, or declare a long variable i instead :D
The best solution would be to upgrade your compiler. Pelles C is a free, popular 32/64 bit C compiler. Turbo C is an old 16 bit compiler that shouldn't be used anymore. Even if you have to use Turbo C for school, you should still download Pelles C and use it whenever possible, so you can get some experience with a modern compiler. Since Turbo C is 6 bit, int types only go from -32768 to +32767. You could try using a bigger data type like long int or long long int. You may need to modify your input function (scanf?) if you do that.
Look up the documentation for scanf, it should tell you how to change your format string to work with long ints. Note, you can try this site, but it might not be correct for Turbo C.
I think you have defined a variable.
Code:#include <stdio.h>
#include <limits.h>
#ifndef __STDC__
#error i should use an newer C compiler
#endif
int i;
long l;
printf("i can use int values up to %d",INT_MAX);
printf("i can use long values up to %ld",LONG_MAX);
The definition of a variable is also a declaration of the variable.Quote:
Originally Posted by BillyTKid
Yes, but not vice versa, what i said.
Any program only with declarations cannot work, only with definitions it works/compiles.
Which is why joybanerjee39's statement is factually correct ;)Quote:
Originally Posted by BillyTKid
I would have expected a linker error instead of a runtime error if the declaration had not been a definition.