长整数 [英] long int

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

问题描述



假设我有以下功能:

长号(无效)

{

long sum = 421;

return(sum * sum);

}


所以,我打印声明("数字是%d",number());结果

是-19367。为什么?我想长时间可以容纳32位。我希望结果

为177241.


谢谢。

Hi,
Let say I have following function:
long number(void)
{
long sum = 421;
return (sum*sum);
}

so, I printf the statement ("Number is %d", number( )); the result
is -19367. Why ? I suppose long can hold up to 32 bits. I expect the result
to be 177241.

Thanks.

推荐答案

Magix写道:


假设我有以下功能:
长号(无效)
{
长和= 421;
返回(sum * sum);
}
所以,我打印语句(Number is%d,number());结果
是-19367。为什么?我想长时间可以容纳32位。我希望结果
是177241。
Hi,
Let say I have following function:
long number(void)
{
long sum = 421;
return (sum*sum);
}

so, I printf the statement ("Number is %d", number( )); the result
is -19367. Why ? I suppose long can hold up to 32 bits. I expect the result
to be 177241.




它是。你只是没有正确输出它。


如果你有一个长,你需要使用'l''格式说明符,而不是

`D '表示';因此你想要:


printf(Number is%l,number());


HTH,

- g


-

Artie Gold - 德克萨斯州奥斯汀


"什么他们指责你 - 是他们的计划。



It is. You just didn''t output it correctly.

If you have a long, you need to use the `l'' format specifier, not the
`d''; hence you want:

printf("Number is %l", number());

HTH,
--ag

--
Artie Gold -- Austin, Texas

"What they accuse you of -- is what they have planned."


Magix写道:
Magix wrote:
让我说我有以下功能:
长号(无效)
{
长和= 421;
返回(总和*总和);
}

所以,我打印语句(Number is%d,number());结果
是-19367。为什么?我想长时间可以容纳32位。我希望结果
为177241。
Let say I have following function:
long number(void)
{
long sum = 421;
return (sum*sum);
}

so, I printf the statement ("Number is %d", number( )); the result
is -19367. Why ? I suppose long can hold up to 32 bits. I expect the result
to be 177241.




格式字符串由零个或多个指令组成:

普通字符(不是%),它被不加改变地复制到输出流中;和转换规范,每个

,这导致零或更多后续争论 -
。每个转换规范由

字符%引入。参数必须与转换说明符正确对应

(类型提升后)。

在%之后,以下内容依次出现...

o可选字符l(ell)指定在d,i,o,u,x或X转换后的

适用于

a指向a long int或unsigned long int argument-

ment,或者跟随n转换对应于
指向long int参数的指针。


Allin Cottrell



The format string is composed of zero or more directives:
ordinary characters (not %), which are copied unchanged to
the output stream; and conversion specifications, each of
which results in fetching zero or more subsequent argu-
ments. Each conversion specification is introduced by the
character %. The arguments must correspond properly
(after type promotion) with the conversion specifier.
After the %, the following appear in sequence...

o The optional character l (ell) specifying that a
following d, i, o, u, x, or X conversion applies to
a pointer to a long int or unsigned long int argu-
ment, or that a following n conversion corresponds
to a pointer to a long int argument.

Allin Cottrell


Magix写道:


假设我有以下功能:
长号(无效)
{长/长= 421;
返回(总和*总和);
}

所以,我打印声明(Number is%d,number());结果
是-19367。为什么?我想长时间可以容纳32位。我希望结果
为177241。
Hi,
Let say I have following function:
long number(void)
{
long sum = 421;
return (sum*sum);
}

so, I printf the statement ("Number is %d", number( )); the result
is -19367. Why ? I suppose long can hold up to 32 bits. I expect the result
to be 177241.



#include< stdio.h>


长号(无效)

{

长期总和= 421;

返回(总和*总和);

}


int main(无效)

{

/ * mha:注意%ld"而不是%d

便携式行为需要''\ n''。 * /

printf(" Number is%ld \ n",number());

返回0;

}


[输出]

数字是177241


#include <stdio.h>

long number(void)
{
long sum = 421;
return (sum * sum);
}

int main(void)
{
/* mha: note the "%ld" rather than "%d" and the ''\n'' needed for
portable behavior. */
printf("Number is %ld\n", number());
return 0;
}

[Output]
Number is 177241


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

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