问题描述
当我执行此code
#include<stdio.h>
int main() {
int (*x)[5];
printf("\nx = %u\nx+1 = %u\n&x = %u\n&x + 1 = %u",x,x+1,&x,&x+1);
}
这是用C或C ++的输出:
This is the output in C or C++:
x = 134513520
x+1 = 134513540
&x = 3221191940
&x + 1 = 3221191944
请解释一下。此外之间有什么区别:
Please explain. Also what is the difference between:
INT X [5]
和 INT(* X)[5]
?
推荐答案
-
INT X [5]
5整数数组 -
INT(* X)[5]
是指针的5个整数数组
int x[5]
is an array of 5 integersint (*x)[5]
is a pointer to an array of 5 integers
当你增加一个指针,您可以通过所指向的类型的大小递增。 X + 1
因此, 5 *的sizeof(INT)
字节不仅仅是放大X
- 给 8048370
和 8048384
的十六进制值与0x14的,或20的差异
When you increment a pointer, you increment by the size of the pointed to type. x+1
is therefore 5*sizeof(int)
bytes larger than just x
- giving the 8048370
and 8048384
hex values with a difference of 0x14, or 20.
&放大器; X
是一个指针的指针 - 所以,当你增加它添加的sizeof(指针)
字节 - 这给 bf9b08b4
和 bf9b08b8
的十六进制值,为4的区别
&x
is a pointer to a pointer - so when you increment it you add sizeof(a pointer)
bytes - this gives the bf9b08b4
and bf9b08b8
hex values, with a difference of 4.
这篇关于问题指针数组的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!