【知识点】数组

struct tagStudent
{
unsigned long num;
unsigned long age;
};

void fun(unsigned long ulLen)
{
printf("%lu\n", ulLen);
}

int main() {

struct tagStudent students[4] = { { 1, 2 },
                                  { 3, 4 },
                                  { 5, 6 },
								  { 7, 8 } };
fun((unsigned long)(students + 2) - (unsigned long)(students));
fun((students + 2) - students);

system("pause");
return 0;

}
结果:
16
2

上面的相当于:

2 * sizeof(struct tagStident) = 2 * 8,上面的由于是student+2在括号里面,因此+2是加上2*结构体的大小

下面的就是简单的地址相减

+++++++++++++

在这里插入图片描述
答案是C:
(1)是struct类型的+1
(2)是(u long类型的)+1,也就是简单的数字+1
(3)是(u long )类型的+1,也就是+1(sizeof(u long))
(4)是(char*)类型的+1,也就是+1*(sizeof(char))

参见:指针,指针+1,就是加上当前类型的大小

发布了44 篇原创文章 · 获赞 1 · 访问量 903

猜你喜欢

转载自blog.csdn.net/weixin_42268479/article/details/105540352