C指针问题 [英] C Pointer problem
问题描述
我无法理解为什么这段代码会导致内存读取异常。在
int x = ** a;
void pass(int ** a)
{
int x = ** a;
}
void main()
{
int arr [2] [2] = {{1,2},{3,4}};
传递(arr);
}
主函数中int int x = ** a的赋值。
坦克为你提供帮助,
Markus
>
推荐答案
Markus说:
Markus said:
我不明白为什么该代码导致存储器读取异常。在
int x = ** a;
void pass(int ** a)
{
int x = ** a;
}
void main()
主要返回int。
如果你甚至无法获得正确的入口点,那么有什么机会你支持
指针吗?
{
int arr [2] [2] = {{1,2},{3,4}};
传递(arr);
Hi,
I can''t understand why this code causes a "memory read exception" at
int x=**a;
void pass(int** a)
{
int x=**a;
}
void main()
main returns int.
If you can''t even get the entry point right, what chance do you stand with
pointers?
{
int arr[2][2]={{1,2},{3,4}};
pass(arr);
pass()接受int **。
arr'的值被视为其第一个元素的地址。它的第一个元素
是一个int [2]数组,所以它的第一个元素的地址类型为int
(*)[2],这与int **。
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然放弃了www)
pass() takes int **.
arr''s value is taken as the address of its first element. Its first element
is an int[2] array, so the address of its first element has type int
(*)[2], which is not the same as int **.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Markus写道:
Markus wrote:
我无法理解为什么这段代码会导致内存读取异常。在
int x = ** a;
void pass(int ** a)
{
int x = ** a;
}
void main()
{arr [2] [2] = {{1,2},{3,4}};
传递(arr);
}
在main函数中赋值int int x = ** a。
Hi,
I can''t understand why this code causes a "memory read exception" at
int x=**a;
void pass(int** a)
{
int x=**a;
}
void main()
{
int arr[2][2]={{1,2},{3,4}};
pass(arr);
}
The assignment of int int x=**a in the main function works.
这是否真的编译没有任何警告或错误?
Brian
Did this really compile without any warnings or errors?
Brian
默认用户说:
Default User said:
Markus写道:
Markus wrote:
我无法理解为什么这段代码会导致内存读取异常。在
int x = ** a;
void pass(int ** a)
{
int x = ** a;
}
void main()
{arr [2] [2] = {{1,2},{3,4}};
传递(arr);
}
在main函数中赋值int int x = ** a。
Hi,
I can''t understand why this code causes a "memory read exception" at
int x=**a;
void pass(int** a)
{
int x=**a;
}
void main()
{
int arr[2][2]={{1,2},{3,4}};
pass(arr);
}
The assignment of int int x=**a in the main function works.
这真的编译没有任何警告或错误吗?
Did this really compile without any warnings or errors?
< br $>
编号
foo.c:2:警告:没有以前的'pass'原型'
foo .c:函数`pass'':
foo.c:3:警告:未使用的变量`x''
foo.c:顶层:
foo.c:6:警告:函数声明不是原型
foo.c:6:警告:返回类型`main''不是`int''
foo.c:在函数`main''中:
foo.c:8:警告:从不兼容的指针类型传递arg 1的'pass'' >
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然放弃了www)
No.
foo.c:2: warning: no previous prototype for `pass''
foo.c: In function `pass'':
foo.c:3: warning: unused variable `x''
foo.c: At top level:
foo.c:6: warning: function declaration isn''t a prototype
foo.c:6: warning: return type of `main'' is not `int''
foo.c: In function `main'':
foo.c:8: warning: passing arg 1 of `pass'' from incompatible pointer type
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
这篇关于C指针问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!