long integer problem

I'm a beginner at C, and using Turbo C++ compiler (16 bit).

In the software I'm writing, the maximum answer is around 32000. If I want a number larger than that, I use long int.

If I execute the following program:

#include <stdio.h>
void main()
    long int x;
    printf("%d", x);

Then I get an error that the constant value is long in function main().

How can I get an answer more that 32000 and get rid of this error? also nw i change %d to %ld and use 40000L bt when i use unsigned integer then also i need to use 'l' with 40000//??


Use %ld in printf for the long int. %d is for int which only has 16 bits in your compiler. And for the error message, use x=40000L.

Change long to unsigned, 40000 will fit in unsigned int.

Assuming you're on windows, the best solution to this is to target a 32 or 64-bit platform. 16-bit programs won't even run on 64-bit versions of windows; you should really upgrade.

Microsoft has a free version of Visual Studio: Visual C++ Express Edition. This is an excellent option also because it comes with a full IDE.

Gcc is also available for windows in the form of Mingw. Unfortunately, mingw itself does not release ready-to-use compilers, but others do, such as equation.com or TDM.

Perhaps brushing up on variadic formatting might help :) By the time you (or the printf() subsystem) actually gets to expanding variadic arguments, its assumed that you know what type they are.

This not only goes for printf, but any other function that employs va_*() or v*printf() when discussing printf. Don't lose track of your types.

Also, keep track of signedness to avoid unexpected results.

In other words, by the time you call printf(), or anything else accepting an elipsis, be sure of what you are passing. This isn't limited to printf(), in fact venturing beyond that will often not produce compiler warnings.

Need Your Help

Why is django giving error: no module named django.core?

python windows django django-admin

I get the error in question when I attempt to create a project. I followed the instructions found at how to install python an django in windows vista.

How do I do these JavaScript date() calls in PHP?

javascript php date math

I need to write a PHP program to get a world population clock value. It will be used with other PHP code for calculations and I need the world population clock real-time estimate for the formula to...