左值要求作为增量操作 [英] lvalue required as increment operand
本文介绍了左值要求作为增量操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
GCC 4.4.4
gcc 4.4.4
也许我哑巴。但我做错了?
Maybe I am being dumb. But what am I doing wrong?
char x[10];
char y[] = "Hello";
while(y != NULL)
*x++ = *y++;
非常感谢任何建议,
Many thanks for any advice,
推荐答案
X ++是的缩写形式X = X + 1。然而,X这里是一个数组,你不能修改数组的地址。因此,与您的变量y的情况了。你能做什么定义两个指针指向两个数组,并增加这些指针或做到以下几点。
x++ is the short form of x = x + 1. However, x here is an array and you cannot modify the address of an array. So is the case with your variable y too. What you can do is defined two pointers pointing to the two arrays and increment those pointers or do the following.
char x[10];
char y[] = "Hello";
int i=0;
while(y[i] != 0)
{
*(x+i) = *(y+i);
i++;
}
x[i] = 0;
这篇关于左值要求作为增量操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文