我可以使用指针访问多维数组? [英] Can I access multidimensional array using a pointer?

查看:124
本文介绍了我可以使用指针访问多维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这参考,在C似乎以下行为是不确定的。

From this reference, In C it seems the following behavior is undefined.

int my_array[100][50];
int *p = my_array[0];
p[50]; // UB

有没有C ++ 03或C ++ 11,证实了这一点?

Is there a reference in C++03 or C++11 which confirms this?

推荐答案

在是+运算符的描述。你可以不解除引用用C该指针,因为它是一个过去的端指针用于第一子阵列。在C ++中这是目前合法的,因为指针的百分点的一个有效的整数(点关系到在第3节的地方定义)。然而,在这两个标准将超过50收益率不确定的行为。

Yes in the description of the + operator. You may not dereference that pointer in C because it is a past the end pointer for the first subarray. In C++ this currently is legal because the pointer points to a valid integer (the points to relation is defined somewhere in clause 3). However in both standards adding more than 50 yields undefined behavior.

一个DR最近发送到C关于解引用这种有效凭空指针可以取消引用的规则++委员会,所以我不会依赖这一点。

A DR was recently sent to the c++ committee about the rule that dereferencing such "valid out of thin air" pointers may be dereferenced, so i would not rely on that.

这篇关于我可以使用指针访问多维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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