长整数问题 [英] long integer problem

查看:43
本文介绍了长整数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 C 的初学者,使用 Turbo C++ 编译器(16 位).

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

在我写的软件中,最大的答案是 32000 左右.如果我想要一个更大的数字,我使用 long int.

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

如果我执行以下程序:

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

然后我得到一个错误,函数main()中的常量值很长.

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

我怎样才能得到超过 32000 的答案并摆脱这个错误?另外,当我使用无符号整数时,我将 %d 更改为 %ld 并使用 40000L bt 然后我还需要将 'l' 与 40000 一起使用//??

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//??

推荐答案

在 printf 中使用 %ld 作为 long int.%d 用于 int ,它在您的编译器中只有 16 位.对于错误消息,请使用 x=40000L.

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.

这篇关于长整数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆