| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3824 人关注过本帖
标题:很愧对老师这个职业,快帮帮我呀!不胜感谢
只看楼主 加入收藏
大水牛
Rank: 1
等 级:新手上路
威 望:1
帖 子:233
专家分:0
注 册:2005-11-21
收藏
得分:0 
其实这个我估计和PC机器有关,在不同型号的PC上CHAR会有不同的空间大小分配,
就像INT型定义有的机器和SHORT是一样的,有些定义和LONG一样。所以大家有些分歧
呵呵
楼主能回复下不

虽然现在的我什么都不明白,但总有一天,我将包容一切,让优秀变成一种习惯。。。。。。。。。。。。
2005-11-21 11:47
Lc_fox
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2005-11-20
收藏
得分:0 

大家这样就知道到底是一个转义字符\n 还是一个字符串\n了

printf("%c",'\n');

getch();

printf("%d",sizeof('\n'));

getch();

应该和字符型数据在内存储器中的存储方式有关吧


Rove_Pro 流浪与编程 http://post.baidu.com/f?kw=rove_pro
2005-11-21 13:12
dx03680
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-11-22
收藏
得分:0 
....

' '里面的东西叫做 字符常量
不是字符串,不管 sizeof()这个运算符 怎么处理这个问题, 字符常量终究是字符常量,' '里面只能装1个字符常量,不是字符串常量.
既然已经明确'\n'是字符,就没有必要想它是不是字符串....
所以 转义字符'\n'必定是一个字符.

既然输出结果为2就得从仔细研究sizeof()的功能入手``

TC2.0测试表明:
sizeof('')==2;sizeof("")==1;sizeof('a')==2;sizeof("a")==2;sizeof("ab")==3;
sizeof("abcdef")==7;
sizeof(int)==2;sizeof(char)==1;sizeof(float)==4;

你能从这点说明'a'是2个字节,"ab"是三个字节?
应该好好抓住定义,从定义来理解'\n'的含义.

sizeof(x) 求出x在内存中所占字节数,取变量或者定义的存储空间的字节数`
x可以是变量,结构,类型,标示...
但是要注意的是sizeof()不是函数,是运算符``
以上的运算结果都是某字符,某字符串或者空串所占用的内存空间大小,不能说明其他问题.

[此贴子已经被作者于2005-11-22 16:13:58编辑过]

2005-11-22 16:06
dx03680
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-11-22
收藏
得分:0 

[此贴子已经被作者于2005-11-22 16:15:04编辑过]


2005-11-22 16:09
wincor
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-12-20
收藏
得分:0 
编译器的问题
2005-12-20 12:37
ryxhh
Rank: 1
等 级:新手上路
威 望:1
帖 子:63
专家分:0
注 册:2005-12-18
收藏
得分:0 

我认为这是编译器的问题,wintc有着许多不严谨的地方,比如指针方面,不经指向可以直接使用,如果这样,可能导致系统不安全.
至于这问题,我在两种编译器中运行有两结果.
在wintc中为2
在vc++中为1


2005-12-20 12:50
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
收藏
得分:0 
我不知道回过这贴,看过这个贴,特别是在靠后面的几个,有没有仔细看别人的贴子?有没有看懂?有没有自己调试过?

九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2005-12-20 15:15
feverxx
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2005-12-20
收藏
得分:0 

A character written between single quotes represents an integer value equal to the numerical value of the character in the machine's character set. This is called a character constant, although it is just another way to write a small integer. So, for example, 'A' is a character constant; in the ASCII character set its value is 65, the internal representation of the character A. Of course, 'A' is to be preferred over 65: its meaning is obvious, and it is independent of a particular character set.

2005-12-22 16:33
feverxx
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2005-12-20
收藏
得分:0 
Be careful to distinguish between a character constant and a string that contains a single character: 'x' is not the same as "x". The former is an integer, used to produce the numeric value of the letter x in the machine's character set. The latter is an array of characters that contains one character (the letter x) and a '\0'.
2005-12-22 16:51
快速回复:很愧对老师这个职业,快帮帮我呀!不胜感谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012641 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved