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.
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
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.
The definition of a variable is also a declaration of the variable.Originally Posted by BillyTKid
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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 correctOriginally Posted by BillyTKid
I would have expected a linker error instead of a runtime error if the declaration had not been a definition.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)