如何打印短整数? [英] how to print a short and long integer?

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

问题描述

短片;

长l;

s = -2;

l = -3;

printf ("%_%_",s,l);

格式化字符串中应填写哪些字符用于输出?

Thanx

解决方案

On Sun,2005年9月25日04:14:29 GMT,a < a@mail.com>写在

comp.lang.c:

short s;
long l;
s = -2;
l = -3;
printf("%_%_",s,l);
在输出的格式化字符串中应填写哪些字符?
Thanx



您的C参考书说什么?


您的编译器的库手册,在线帮助文​​件或人< br $>
页面告诉你?

为什么你认为usenet可以代替在标准参考文献中查找基本的

信息?


在google.com的搜索框中键入此字符串:


printf" conversion specifiers"


....并按照第一个链接。


-

Jack Klein

主页: http://JK-Technology.Com


$常见问题b $ b comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


----- BEGIN PGP签名消息-----

哈希:SHA1


a写道:

短s;
长l;
s = -2;
l = -3;
printf("%_%_",s,l);
应该在格式化的字符串中填写哪些字符用于输出?




printf("%d%ld",s,l);


printf是一个可变函数,因此它的原型不包含大多数参数的定义

(仅定义了格式字符串参数) 。

因此,对于其他参数,标准促销规则适用:

- - short int promote to int

- - long int保持为long int


每个参数的格式字符串必须预期

参数的格式。 %d用于int,因此它将用于一个short int,它将

提升为int。 %ld用于long int。


- -

Lew Pitcher


Master Code代理& JOAT-in-training |可根据要求提供GPG公钥

注册Linux用户#112576( http:/ /counter.li.org/

Slackware - 因为我知道我在做什么。

----- BEGIN PGP SIGNATURE-- ---

版本:GnuPG v1.2.7(GNU / Linux)

iD8DBQFDNiVjagVFX4UWr64RAgHHAJ0REEuapZyZpblfFP5V4d WEZMRBEgCgxzwB

6moAzVtg16kHNGrjWNmua7A =

= Djbp

-----结束PGP SIGNATURE -----


a写道:

短s;
long l;
s = -2;
l = -3;
printf("%_%_",s,l);
格式化字符串中应填写哪些字符用于输出?
Thanx




#include< stdio.h>

int main(无效)

{

短s = -2;

长l = -3;

printf("标准方式使用\'%% hd %% ld \":%hd%ld \ n",s,l );

printf(" (但是\%% d %% ld \应该也能正常工作:%d%ld \ n",s,l);

返回0;

}

标准方式使用%hd%ld:-2 -3

(但%d%ld应该也能正常工作:-2 -3


short s;
long l;
s= -2;
l= -3;
printf("% _ %_",s, l);
What characters should be filled out in the formatted string for output?
Thanx

解决方案

On Sun, 25 Sep 2005 04:14:29 GMT, "a" <a@mail.com> wrote in
comp.lang.c:

short s;
long l;
s= -2;
l= -3;
printf("% _ %_",s, l);
What characters should be filled out in the formatted string for output?
Thanx



What does your C reference book say?

What does your compiler''s library manual, online help file, or man
pages tell you?

Why do you think usenet is a substitute for looking up basic
information in standard references?

Type this string into the search box at google.com:

printf "conversion specifiers"

....and follow the first link.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

a wrote:

short s;
long l;
s= -2;
l= -3;
printf("% _ %_",s, l);
What characters should be filled out in the formatted string for output?



printf("%d %ld",s,l);

printf is a variadic function, so it''s prototype does not include definitions
for most of it''s arguments (only the format string argument is defined).

Thus, for the other arguments, the standard promotion rules apply:
- - short int promotes to int
- - long int stays as long int

The format strings for each argument must anticipate the format of the
arguments. %d is used for int, so it will be used for a short int which gets
promoted to int. %ld is used for long int.

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I''m doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFDNiVjagVFX4UWr64RAgHHAJ0REEuapZyZpblfFP5V4d WEZMRBEgCgxzwB
6moAzVtg16kHNGrjWNmua7A=
=Djbp
-----END PGP SIGNATURE-----


a wrote:

short s;
long l;
s= -2;
l= -3;
printf("% _ %_",s, l);
What characters should be filled out in the formatted string for output?
Thanx



#include <stdio.h>
int main(void)
{
short s = -2;
long l = -3;
printf("The standard way using \"%%hd %%ld\": %hd %ld\n", s, l);
printf(" (but \"%%d %%ld\" should work as well: %d %ld\n", s, l);
return 0;
}
The standard way using "%hd %ld": -2 -3
(but "%d %ld" should work as well: -2 -3


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

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