帮助* x ++ = * y ++; [英] Help for *x++=*y++;
问题描述
这个表达式到底是做什么的。
* x ++ = * y ++;
x和y都是char指针。
x指向p_ch它指向C字符串。
$ b $确实直接指向C-Strings。
我知道后增量运算符
的优先级高于
解除引用运算符。
....
p_ch = cstring;
x = p_ch;
* x =''\''';
* x ++ = * y ++;
....
''\ 0''会发生什么(* x =''\''';?
有人知道吗?
thx
What does this expression exactly do.
*x++=*y++;
x and y are both char pointers.
x points on p_ch which points on a C-string.
y indeed points directly on a C-Strings.
I know that the post-increment operator
has got a higher priority than the
dereference operator.
....
p_ch=cstring;
x=p_ch;
*x=''\0'';
*x++=*y++;
....
What happens with the ''\0'' (*x=''\0''; ?
Does somebody know?
thx
推荐答案
" Marco Stauder"< go ***** @ gmx.de>写道......
"Marco Stauder" <go*****@gmx.de> wrote...
这个表达式到底是做什么的。
* x ++ = * y ++;
x和y都是char指针。
x点在p_ch上指向一个C弦。
确实直接指向一个C弦。
我知道这个位置t-increment运算符
比
解引用运算符具有更高的优先级。
正确。
事件链类似于
// - 开始表达式
char c = * y; //暂时的
y = y + 1; //不一定在这里,但肯定是
//在原始expr结束之前
* x = c;
x = x + 1;
// - 结束表达
...
p_ch = cstring;
x = p_ch;
* x =''\''';
这似乎没必要。
* x ++ = * y ++;
...
什么发生在''\ 0''(* x =''\''';?
你是什么意思,会发生什么事情?
有人知道吗?
What does this expression exactly do.
*x++=*y++;
x and y are both char pointers.
x points on p_ch which points on a C-string.
y indeed points directly on a C-Strings.
I know that the post-increment operator
has got a higher priority than the
dereference operator.
Correct.
The chain of events is similar to
// -- beginning of the expression
char c = *y; // a temporary
y = y + 1; // not necessarily here, but certainly
// before the end of the original expr
*x = c;
x = x + 1;
// -- end of the expression
...
p_ch=cstring;
x=p_ch;
*x=''\0'';
This doesn''t seem necessary.
*x++=*y++;
...
What happens with the ''\0'' (*x=''\0''; ?
What do you mean "what happens"?
Does somebody know?
无论是谁写的都可能知道。
Victor
Whoever wrote it probably knows.
Victor
" Marco Stauder"< go ***** @ gmx.de>在消息新闻中写道:rg *********** ********************* @ 4ax.com ...
\
"Marco Stauder" <go*****@gmx.de> wrote in message news:rg********************************@4ax.com...
\
我知道后增量运算符
比
解引用运算符具有更高的优先级。
这个词是优先的。是的你是对的。
* x ++表示*(x ++)。
(不是(* x)++)。
...
p_ch = cstring;
x = p_ch;
* x =''\''';
上面被下一行删除。* x ++ = * y ++;
I know that the post-increment operator
has got a higher priority than the
dereference operator.
The word is precedence. Yes you are right.
*x++ means *(x++).
(not (*x)++).
...
p_ch=cstring;
x=p_ch;
*x=''\0''; The above obliterated by the next line. *x++=*y++;
表达式x ++和y ++都产生了原始值x和y
(在增量之前),因此从最初指向x最初指向的位置y
分配一个字符。此外,x和
y都会增加到指向下一个字符。
char str [] =" 0123456789";
x = str;
y =" abcdefghij";
* x ++ = * y ++;
将''a''移动到str中的''0'。
x和y递增(所以x现在是str + 1,指向''1''和y指着b)。
The expressions x++ and y++ both yield the original values of x and y
(before the increment), so one character is assigned from the where y
originally pointed to where x originally pointed. In addition, both x and
y are incremented to point at the next character.
char str[] = "0123456789";
x = str;
y = "abcdefghij";
*x++ = *y++;
moves the ''a''in y to the ''0'' in str.
x and y are incremented (so x is now str+1, pointing at the ''1'' and y is pointing at the b).
在文章< rg ******************* *************@4ax.com>,
Marco Stauder< go ***** @ gmx.de>写道:
In article <rg********************************@4ax.com>,
Marco Stauder <go*****@gmx.de> wrote:
这个表达式到底是做什么的。
* x ++ = * y ++;
#include< iostream>
使用命名空间std;
void foo(char * x,const char * y)
{
char * start_of_x = x;
while(* y){
cout<< start_of_x<< " " << (int)x<< " " << (int)y<< endl;
* x ++ = * y ++;
}
}
int main()
{
const char * b =" abcdefg" ;;
char * a = new char [8];
//以下是严格必要的吗?我不这么认为,但我不确定。
for(int i = 0; i< 8; ++ i)
a [i] = 0;
foo(a,b);
cout<< a;
}
它是什么样的* x ++ = * y ++在上面做了什么?
x和y都是char指针。
x点在p_ch上指向一个C字符串。
y确实直接指向一个C字符串。
我知道后增量运算符
比
解引用运算符具有更高的优先级。
我不得不猜测下面的类型。你已经声明
x和y是char *所以我假设p_ch和cstring也是char *'。
...
p_ch = cstring;
现在p_ch和cstring都指向同一个地方。 X = P_CH;
,因此是x * x =''\''';
现在p_ch,cstring和x指向的一个地方包含一个
''\'''* x ++ = * y ++;
现在该地方包含y指向的地方
所包含的相同值。 p_ch和cstring仍然指向那个地方,但是
x指向下一个地方。
''\ 0''会发生什么(* x =''\\ \\ 0'';?
有人知道吗?
What does this expression exactly do.
*x++=*y++;
#include <iostream>
using namespace std;
void foo( char* x, const char* y )
{
char* start_of_x = x;
while ( *y ) {
cout << start_of_x << " " << (int)x << " " << (int) y << endl;
*x++ = *y++;
}
}
int main()
{
const char* b = "abcdefg";
char* a = new char[8];
// is the below strictly necessary? I don''t think so but am not sure.
for ( int i = 0; i < 8; ++i )
a[i] = 0;
foo( a, b );
cout << a;
}
What does it look like "*x++ = *y++" is doing in the above?
x and y are both char pointers.
x points on p_ch which points on a C-string.
y indeed points directly on a C-Strings.
I know that the post-increment operator
has got a higher priority than the
dereference operator.
I''m having to guess the types on the below. You have already stated that
x and y are char* so I''m assuming that p_ch and cstring are also char*''s.
...
p_ch=cstring; now p_ch and cstring are both pointing to the same place. x=p_ch; and so is x *x=''\0''; now that one place that p_ch, cstring, and x is pointing to contains a
''\0'' *x++=*y++; now that place contains the same value that was contained by the place
that y was pointing to. p_ch and cstring still point to that place, but
x points to the next place.
What happens with the ''\0'' (*x=''\0''; ?
Does somebody know?
\ 0没有任何反应。有些事情发生在x是的地方
指向,但它设置为''\0''。
Nothing happens to the ''\0''. Something happens to the place that x is
pointing to though, it is set to ''\0''.
这篇关于帮助* x ++ = * y ++;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!