数组c的声明和赋值? [英] C array declaration and assignment?

查看:147
本文介绍了数组c的声明和赋值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问过类似的问题在结构这里但我想弄清楚ç如何处理之类的东西分配变量,为什么不允许将它们分配给海誓山盟,如果他们在功能上是相同的。

I've asked a similar question on structs here but I'm trying to figure out how C handles things like assigning variables and why it isn't allowed to assign them to eachother if they are functionally the same.

可以说我有两个数组:

int x[10];  
int y[10];

为什么不X = Y编译?如果他们都是相同的签名这样,那么你不应该能够将它们分配来回?

Why won't x = y compile? If they are both the same "signature" like that, then shouldn't you be able to assign them back and forth?

我可以的方式,将允许我这样做,在C声明这些?这是有道理的,我认为你将能够,但也许有一个办法,这可怎么办?对于结构类型定义似乎是解决方案,这将是数组声明和赋值一样吗?

Can I declare these in a way that would allow me to do that in C? It makes sense to me that you would be able to, but maybe there is a way that this can be done? Typedefs for structs seemed to be the solution, would it be the same for array declaration and assignment?

我AP preciate你的球员的帮助,​​我是新来的StackOverflow,但它一直是我的一个很好的资源为止!

I appreciate your guys help, I'm new to Stackoverflow but it has been a really good resource for me so far!

推荐答案

数组的名称实际上是该数组的第一个元素的地址。

The name of an array is actually the address of the first element of that array.

您在这里提供的例子code试图分配到的东西是不是一个左值。

The example code you provide here is attempting to assign to something which is not an l-value.

这就像这样做;

int
  x[10],
  y[10];

&x[0] = &y[0];

您可以用结构你在这里得到什么做什么;

You can do with structs what you're getting at here;

struct data
  a,
  b;

a = b;

而事实上,如果结构数据被声明为;

And in fact if struct data is declared as;

struct data
{
  int
    x[10];
};

那么你会做你想在这里做什么!

then you'd be doing exactly what you're trying to do here!

但你不能直接使用数组做到这一点。使用的memcpy()。

But you can't do it directly with arrays. Use memcpy().

这篇关于数组c的声明和赋值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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