boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - Array in C
相关主题
问个c语言的问题
呼叫THRUST等C语言牛牛,菜鸟级C语言指针问题
c的问题
difference between: char** p and char*p[] ??
strcat()
C 语言,初学者,简单问题
数组问题
how to get this size?
谁给解释一下这个c question
array和pointer在作为函数返回时有啥区别 (C)
相关话题的讨论汇总
话题: abc话题: array话题: p1话题: hello话题: p2
进入Programming版参与讨论
1 (共1页)
i**p
发帖数: 902
1
Could anybody explain why statement 3 works?
char abc[30];
1. strcpy(&(abc[0], "Hello");
2. strcpy(abc ,"Hello");
3. strcpy(&abc ,"Hello");
k****f
发帖数: 3794
2
works不等于正确,
会有后遗症的

【在 i**p 的大作中提到】
: Could anybody explain why statement 3 works?
: char abc[30];
: 1. strcpy(&(abc[0], "Hello");
: 2. strcpy(abc ,"Hello");
: 3. strcpy(&abc ,"Hello");

t****t
发帖数: 6806
3
http://c-faq.com/aryptr/aryvsadr.html

【在 i**p 的大作中提到】
: Could anybody explain why statement 3 works?
: char abc[30];
: 1. strcpy(&(abc[0], "Hello");
: 2. strcpy(abc ,"Hello");
: 3. strcpy(&abc ,"Hello");

i**p
发帖数: 902
4
So based on the explaniation in this web page, I have following:
char abc[30];
abc reference to a has type ``pointer to char,'' and &abc is ``pointer to
array of 10 chars.''
we should use &abc for a string, but mostly we use abc. Please comment.

【在 t****t 的大作中提到】
: http://c-faq.com/aryptr/aryvsadr.html
b******a
发帖数: 215
5
actually &abc and abc point to the same address.
the different is when you set
char (*p1)[30]=&abc;
p1+=1;
char* p2=abc;
p2+=1;
p1+1 and p2+1 will point to different address,
say p2=p1=0x000010, p1+1 will make p1 point to 0x00010+ 1E*sizeof(char);
p2+1 will point to 0x00010+1*sizeof(char)

【在 i**p 的大作中提到】
: So based on the explaniation in this web page, I have following:
: char abc[30];
: abc reference to a has type ``pointer to char,'' and &abc is ``pointer to
: array of 10 chars.''
: we should use &abc for a string, but mostly we use abc. Please comment.

t****t
发帖数: 6806
6
comment: you are wrong, and please read the whole chapter of FAQ.

【在 i**p 的大作中提到】
: So based on the explaniation in this web page, I have following:
: char abc[30];
: abc reference to a has type ``pointer to char,'' and &abc is ``pointer to
: array of 10 chars.''
: we should use &abc for a string, but mostly we use abc. Please comment.

k****f
发帖数: 3794
7
哈哈,你太nice了。

【在 t****t 的大作中提到】
: comment: you are wrong, and please read the whole chapter of FAQ.
t****t
发帖数: 6806
8
that... really depends on the type of p1 and p2. if p1 and p2 are of the
same type,
your p1+1 and p2+1 will be the same anyway. if you say (&abc)+1 and abc+1
are different, that makes more sense.

【在 b******a 的大作中提到】
: actually &abc and abc point to the same address.
: the different is when you set
: char (*p1)[30]=&abc;
: p1+=1;
: char* p2=abc;
: p2+=1;
: p1+1 and p2+1 will point to different address,
: say p2=p1=0x000010, p1+1 will make p1 point to 0x00010+ 1E*sizeof(char);
: p2+1 will point to 0x00010+1*sizeof(char)

b******a
发帖数: 215
9
哈哈。又被你老给找出毛病来了。

【在 t****t 的大作中提到】
: that... really depends on the type of p1 and p2. if p1 and p2 are of the
: same type,
: your p1+1 and p2+1 will be the same anyway. if you say (&abc)+1 and abc+1
: are different, that makes more sense.

o**o
发帖数: 3964
10
why do you guys need +1 in the first place? didn't see that in OP's post

【在 t****t 的大作中提到】
: that... really depends on the type of p1 and p2. if p1 and p2 are of the
: same type,
: your p1+1 and p2+1 will be the same anyway. if you say (&abc)+1 and abc+1
: are different, that makes more sense.

p*u
发帖数: 2454
11
呵呵,it天天守在这。

【在 b******a 的大作中提到】
: 哈哈。又被你老给找出毛病来了。
1 (共1页)
进入Programming版参与讨论
相关主题
array和pointer在作为函数返回时有啥区别 (C)
问一个 char * 和 char [] 的问题
C 语言,初学者问题(4),读取字符指针内容
c# question: char_array.ToString() is not working ?
关于 exception 的一个问题
请帮忙看看这个字符函数的错误在哪里
问个char*的问题
请教一个C里面string copy的问题
What is wrong with the constructor calling?
C++ STL map find does not work ???
相关话题的讨论汇总
话题: abc话题: array话题: p1话题: hello话题: p2