问题描述
嗨伙计,
#include< stdio.h>
int main()
{
int(* p)[10];
int arr [10];
int i;
p = arr; / *< - 编译警告* /
for(i = 0; i< = 12; i ++){/ * i< = 12代替编写代码* /
*((* p)+ i)= i;
printf("%d \ n",p [0] [i]);
}
返回0;
}
在上面的程序中,编译器提供以下内容警告
$ gcc pointer2array.c
pointer2array.c:函数`main'':
pointer2array.c:8 :警告:从不兼容的指针类型分配
为什么警告?
O''kay和int的用法是什么(* p )[10]声明类型?
编译器是否对数组边界执行任何检查?
如果我声明int arr [12] ...
-Neo
Hi Folks,
#include<stdio.h>
int main()
{
int (*p)[10];
int arr[10];
int i;
p = arr; /* <-- compiler warning */
for(i=0; i <= 12; i++){ /* i <=12 delibrately written code */
*((*p) + i) = i;
printf("%d\n", p[0][i]);
}
return 0;
}
In the above program compiler is giving following warning
$gcc pointer2array.c
pointer2array.c: In function `main'':
pointer2array.c:8: warning: assignment from incompatible pointer type
Why the warning?
O''kay and what is the use of int (*p)[10] type of declaration ?
Does the compiler perform any check on the array bounds?
lets say if i declare int arr[12]...
-Neo
推荐答案
-
Jack Klein
主页:
常见问题解答
comp.lang.c
comp.lang.c ++
alt。 comp.lang.learn.c-c ++
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
这篇关于指向int数组的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!