不明白为什么两个表达式是相同的 [英] Don't understand why two expressions are the same
本文介绍了不明白为什么两个表达式是相同的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
char multi [3] [10];
printf(地址是%p / n,多+ 3);
printf(地址是%p \ n,*(多+ 3));
解除引用的地址与地址相同... 。为什么?
*(多+ 3)是否作为数组的名称而是指针?
我尝试了什么:
让程序得到相同的地址......并且不明白怎么样地址
当解除引用时与地址本身相同
char multi[3][10];
printf("Address is %p/n",multi + 3);
printf("Address is %p\n",*(multi + 3));
The dereferenced address is the same as the address .... Why?
Is *(multi + 3) acting as the name of an array and is therefor a pointer?
What I have tried:
Ran the program got the same address ... and dont't understand how an address
when dereferenced is the same as the address itself
推荐答案
这很复杂,但它与什么类型<$ c有关$ c>多是。
是char
?不 - 显然不是。
是指向char
的指针?没有。
那么它是什么?
multi
是一个包含三个元素的数组,每个元素都是一个数组10char
值。
那么多+ 3到底是什么?基本上,这是一个非法地址, 恰好在有效的内存空间 ,因为multi
只有三个元素:多
+ 0,多
+ 1,多
+ 2.
因为你根本没有初始化你的数组,所以multi
+ 3的值最有可能是第一个char $的
multi [0]
数组中的实际char
数据的值c $ c> s,这可能是 - 但不是肯定的,这取决于你的编译器和编译器选项 - 0.
基本上,不要这样做。 br />
尝试使用有效地址,您会得到不同的结果,如您所料。
This is complicated, but it has to do with what typemulti
is.
Is it achar
? No - obviously not.
is it a pointer to achar
? No.
So what is it?
multi
is an array of three elements, each of which is an array of 10char
values.
So what the heck is "multi + 3"? basically, it's an illegal address, which happens to be within the valid memory space becausemulti
has only three elements:multi
+ 0,multi
+ 1, andmulti
+ 2.
And because you don't initialise your array at all, the value of "multi
+ 3" is most likely to be the first value of the actualchar
data in themulti[0]
array ofchar
s, which is probably - but not definately, it depends on your compiler and compiler options - 0.
Basically, don't do it.
Try it with valid addresses, and you get different results, as you would expect.
这篇关于不明白为什么两个表达式是相同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文