C和指针一条题目请问


C和指针一条题目请教?
int array [20];
int *ptr=array; 
问 ptr+1指向哪里?
我的答案是指向
array[1]

C++/VC 程序开发 异常处理

fcaass 10 years, 11 months ago


应该写成这样int array[20];
int **ptr=&array;
看清楚了...

areorer answered 10 years, 11 months ago


int array [20];
int **ptr=array; //编译出错,不信你看。。。

穿刺海豹之枪 answered 10 years, 11 months ago


使用指针还是谨慎为好。

Senoya answered 10 years, 11 months ago


以下是我的理解:


int a[N][M];
int *p;

前者的内存分配一定是连续的,例如 a[k][M-1] 的地址和 a[k+1][0] 的地址一定是连续的 (k+1 < N)

所以,在作为参数传递的时候,可以自动退化成 int (
a)[M] 
(*a)[M] 是个指针,指向一数组
看 这个指针如何初始化

  C/C++ code

  typedef int (*A)[10]; A a; a = (A)malloc(sizeof(int) * 10);

夏娜俺D嫁 answered 10 years, 11 months ago


<fieldset> <legend> 探讨 </legend>
我前面好像改的不对,既然你只是要知道它指向什么,那么我认为
指向地址 &array + 1
</fieldset>


NINITA answered 10 years, 11 months ago


这题目坑人的,,

╲午夜秣班車 answered 10 years, 11 months ago


int **ptr是指向指针的指针。

curry科里 answered 10 years, 11 months ago


不是,它根本没有指向array的内容,而只是在array的地址上加了1而已,这个地址很可能是未分配的

dafanxu answered 10 years, 11 months ago


我前面好像改的不对,既然你只是要知道它指向什么,那么我认为
指向地址 &array + 1

风吹鸡鸡摇 answered 10 years, 11 months ago


<fieldset> <legend> 探讨 </legend>
引用:
int array [20];
int **ptr=array; —— 这个不能赋值吧?

C和指针273页,题目2
暂时不讨论编译器问题,假如可以答案是什么?
</fieldset>


薛定谔的闪闪 answered 10 years, 11 months ago


<fieldset> <legend> 探讨 </legend>

那答案是什么?
引用:
引用:

int **ptr=array; 编译通不过

CODEBLOCKS中可以编译通过,但会报警告.
</fieldset>


大绵羊怪叔叔 answered 10 years, 11 months ago


如果编译都通不过。那讨论指向哪个内存数据好象无意义吧

身体变的好奇怪 answered 10 years, 11 months ago


<fieldset> <legend> 探讨 </legend>
int array [20];
int **ptr=array; —— 这个不能赋值吧?
</fieldset>


路过一下下 answered 10 years, 11 months ago

Your Answer