#include<stdio.h>
void change(int (*arr)[10]){
// manipulate
}
int main(){
int arrM[10]={1,2,3,4,5,6,7,8,9,0};
change(&arrM)
}
我知道 arrM 是一个常量指针,不能更改或分配,而且它不能像 **argv 一样作为指向指针的指针传递,因为它退化为数组指针而不是指向指针的指针.但我的问题是“这是设计的方式,以保护数组的初始内存不被覆盖(如果是,如何?)或者是否有一种机制可以进入//manipulate 区域,可以改变常量指针arrM的值"
最佳答案
I am aware that the arrM is a constant pointer and cannot be changed or assigned
数组名称 (arrM) 不应被视为指针,将其视为 const 类型太过分了。
这post ,几乎可以回答您的问题。
Is this the way the design goes so as to protect the array's initial memory from not getting overwritten(if yes the how?) or is there a mechanism that can get into the //manipulate region that can change the constant pointer arrM's value
数组的初始内存没有被“保护”。您可以声明一个指针,指向数组的第一个元素,并使用指针算法“覆盖”数组。
关于无论如何都可以更改数组的默认指针吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23004421/