将数组地址分配给整数变量,反之亦然 [英] assigning array addresses to integer variables and vice versa
问题描述
我有几个与阵列地址有关的问题。因为他们属于同一个街区的
,所以我把它们放在一个单独的帖子中。我希望没有人介意:
char数组[35];
int地址;
问题1:
为什么我不能做以下事情:
地址=(int)数组;
而我发现完成以下任务非常顺利:
地址=(int)&数组;
问题2:
数组和&数组有什么区别。是不是他们一样
的事情即开始
数组的地址。
问题3:
为什么我不能做array ++。数组指针是否常量?
问题4:
如何执行以下操作:
array =地址;
ie给阵列一个新的起始地址。有可能吗?
提前感谢所有回复。
A.
I have couple of questions related to array addresses. As they belong
to the same block, I
am putting them here in one single post. I hope nobody minds:
char array[35];
int address;
Questions 1:
Why cannot I do the following:
address = (int)array;
whereas I found it perfectly alright to do the following:
address = (int)&array;
Question 2:
What is the difference between array and &array. Are not they the same
thing i.e. starting
address of the array.
Question 3:
Why cannot I do array++. Is array a pointer constant?
Question 4:
How can I do the following:
array = address;
i.e. Give a new starting address to the array. Is it possible?
Thanks in advance for all Your replies.
A.
推荐答案
" anonymous" < CA ****** @ yahoo.com>在消息中写道
news:11 ********************* @ z14g2000cwz.googlegro ups.com ...
"anonymous" <ca******@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
我有几个与数组地址有关的问题。由于他们属于同一个街区,我将他们放在一个单独的帖子里。我希望没有人介意:
char数组[35];
int地址;
问题1:
为什么我不能这样做以下:
地址=(int)数组;
然而我发现完全可以做到以下几点:
地址=(int)& ;数组;
问题2:
数组和&数组有什么区别。是不是一样的东西,即开始阵列的地址。
问题3:
为什么我不能做数组++。数组指针是否常数?
问题4:
如何执行以下操作:
array = address;
即给数组的新起始地址。有可能吗?
提前致谢所有回复。
问题1:
为什么我不能执行以下操作:
address =(int)array;
你做什么''做不到'?
问题2:
有什么区别数组和&数组。是不是它们是相同的,即起始
数组名称分解为其第一个元素的地址,即
常量。你显然不能取一个''值'的地址,所以& array
没有意义,我假设编译器对自己说''好吧,好吧,
我知道他的意思''。
问题3:
为什么我不能做数组++。数组是指针常量吗?
因为数组名称会分解为第一个元素的地址,所以
就像说42 ++;
问题4:
如何执行以下操作:
array = address;
I have couple of questions related to array addresses. As they belong
to the same block, I
am putting them here in one single post. I hope nobody minds:
char array[35];
int address;
Questions 1:
Why cannot I do the following:
address = (int)array;
whereas I found it perfectly alright to do the following:
address = (int)&array;
Question 2:
What is the difference between array and &array. Are not they the same
thing i.e. starting
address of the array.
Question 3:
Why cannot I do array++. Is array a pointer constant?
Question 4:
How can I do the following:
array = address;
i.e. Give a new starting address to the array. Is it possible?
Thanks in advance for all Your replies. Questions 1:
Why cannot I do the following: address = (int)array;
What do you by ''can''t do''?
Question 2:
What is the difference between array and &array. Are not they the same
thing i.e. starting
an array name decomposes into the address of its first element, i.e., a
constant. You obviously cannot take the address of a ''value'', and so &array
doesn''t make sense, and I assume the compiler''s saying to itself ''well, ok,
I know what he means''.
Question 3:
Why cannot I do array++. Is array a pointer constant?
Because an array name decomposes into the address of its first element, so
it''s like saying 42++;
Question 4:
How can I do the following:
array = address;
你不能,它就像说42 = 24;
You can''t, it''d be like saying 42 = 24;
anonymous写道:
anonymous wrote:
我有几个与数组地址有关的问题。由于他们属于同一个街区,我将他们放在一个单独的帖子里。我希望没有人介意:
char数组[35];
int地址;
问题1:
为什么我不能这样做以下:
地址=(int)数组;
不,这是一种合法的语法。但是,指向整数转换的指针可能会导致
调用未定义的行为,如果结果不能用整数表示
类型。
而我发现它完全没问题以下:
地址=(int)&数组;
问题2:
数组和&数组有什么区别。是不是它们相同的东西,即启动数组的地址。
数组和&数组在值上下文中相同,都会在值上下文中产生指向
第一个元素的指针。
问题3:
为什么我不能做array ++。数组是指针常量吗?
后缀增量运算符需要一个可修改的l值。数组名称是
不是可修改的l值。
问题4:
如何执行以下操作:
array =地址;
即为数组提供一个新的起始地址。可能吗?
I have couple of questions related to array addresses. As they belong
to the same block, I
am putting them here in one single post. I hope nobody minds:
char array[35];
int address;
Questions 1:
Why cannot I do the following:
address = (int)array;
No, it is a legal syntax. However pointer to integer conversion may
invoke undefined behavior if result cannot be represented in integer
type.
whereas I found it perfectly alright to do the following:
address = (int)&array;
Question 2:
What is the difference between array and &array. Are not they the same
thing i.e. starting
address of the array.
array and &array are same in value context, both yield pointer to
first element in value context.
Question 3:
Why cannot I do array++. Is array a pointer constant?
postfix increment operator needs a modifiable l-value. array name is
not a modifiable l-value.
Question 4:
How can I do the following:
array = address;
i.e. Give a new starting address to the array. Is it possible?
不,见上文。
Krishanu
No, see above.
Krishanu
pemo写道:
pemo wrote:
" anonymous" < CA ****** @ yahoo.com>在消息中写道
新闻:11 ********************* @ z14g2000cwz.googlegro ups.com ...
"anonymous" <ca******@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I有几个与数组地址有关的问题。由于他们属于同一个街区,我将他们放在一个单独的帖子里。我希望没有人介意:
char数组[35];
int地址;
问题1:
为什么我不能这样做以下:
地址=(int)数组;
而我发现完全可以做到以下几点:
address =(int)& ;数组;
问题2:
数组和&数组有什么区别。是不是一样的东西,即开始阵列的地址。
问题3:
为什么我不能做数组++。数组指针是否常数?
问题4:
如何执行以下操作:
array = address;
即给数组的新起始地址。是否有可能?
提前感谢所有回复。
I have couple of questions related to array addresses. As they belong
to the same block, I
am putting them here in one single post. I hope nobody minds:
char array[35];
int address;
Questions 1:
Why cannot I do the following:
address = (int)array;
whereas I found it perfectly alright to do the following:
address = (int)&array;
Question 2:
What is the difference between array and &array. Are not they the same
thing i.e. starting
address of the array.
Question 3:
Why cannot I do array++. Is array a pointer constant?
Question 4:
How can I do the following:
array = address;
i.e. Give a new starting address to the array. Is it possible?
Thanks in advance for all Your replies.
问题1:
为什么我不能执行以下操作:
Questions 1:
Why cannot I do the following:
> address =(int)array;
>address = (int)array;
你做什么''不能做'?
What do you by ''can''t do''?
>
哎呀,再次检查,完全没问题
地址=(int)数组;
我的错在哪里。
Ooops, checking again, it is perfectly alright to do
address = (int)array;
My fault somewhere.
问题2:
数组和&数组有什么区别。是不是它们是相同的,即开始
数组名称分解为其第一个元素的地址,即
常量。你显然不能取一个''值'的地址,所以& array
没有意义,我假设编译器对自己说''好吧,好吧,>我知道他的意思''。
Question 2:
What is the difference between array and &array. Are not they the same
thing i.e. starting
an array name decomposes into the address of its first element, i.e., a
constant. You obviously cannot take the address of a ''value'', and so &array
doesn''t make sense, and I assume the compiler''s saying to itself ''well, ok,
I know what he means''.
为什么在这里所有其他时间一直在抱怨时如此自由。我的意思是
编译器:-)
Why so liberty here when it keeps complaining all other times. I mean
the compiler :-)
问题3:
为什么我不能做array ++。数组是指针常量吗?
Question 3:
Why cannot I do array++. Is array a pointer constant?
因为数组名称会分解为第一个元素的地址,所以
就像说42 ++;
Because an array name decomposes into the address of its first element, so
it''s like saying 42++;
问题4:
如何执行以下操作:
array = address;
Question 4:
How can I do the following:
array = address;
你不能,这就像说42 = 24;
You can''t, it''d be like saying 42 = 24;
感谢您的帮助。
Thanks for your help.
这篇关于将数组地址分配给整数变量,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!