指针和数组。 [英] Pointers and arrays.

查看:67
本文介绍了指针和数组。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< string.h>

#include< stdio.h>

#include< windows.h>

int main(int argc,char * argv [])

{


char s [10] =" welcome";


char * p = s;

char ** prt = p; //错误发生在这里

返回0;

}

#include <string.h>
#include <stdio.h>
#include <windows.h>
int main(int argc, char *argv[])
{

char s[10] = "welcome";

char *p = s;
char **prt = p; //error happens here
return 0;
}

推荐答案



" raashid bhatt" < ra ********** @ gmail.comwrote in message

news:7c ******************** ************** @ t1g2000p ra.googlegroups.com ...

"raashid bhatt" <ra**********@gmail.comwrote in message
news:7c**********************************@t1g2000p ra.googlegroups.com...

#include< string.h>

#include< stdio.h>

#include< windows.h>
#include <string.h>
#include <stdio.h>
#include <windows.h>



< windows.his不是标准C头。请

省略此处发布的代码(无论如何都没有

与你的问题有关)。

<windows.his not a standard C header. Please
omit such from code posted here (it has nothing
to do with your question anyway).


>


int main(int argc,char * argv [])

{


char s [10] =" welcome";


char * p = s;

char ** prt = p; //错误发生在这里
>

int main(int argc, char *argv[])
{

char s[10] = "welcome";

char *p = s;
char **prt = p; //error happens here



那是因为你试图分配

一个不兼容的类型。写道:


char ** prt =& p;

That''s because you''re trying to assign
an incompatible type. Write:

char **prt = &p;


返回0;

}
return 0;
}



我已经向您展示了正确的语法。但是你想要做什么呢?b
$ b -Mike


I''ve shown you correct syntax. But what
exactly are you trying to do?

-Mike


8月19日, 6:54 * am,Mike Wahler < mkwah ... @ mkwahler.netwrote:
On Aug 19, 6:54*am, "Mike Wahler" <mkwah...@mkwahler.netwrote:

" raashid bhatt" < raashidbh ... @ gmail.com写信息


新闻:7c *********************** *********** @ t1g2000p ra.googlegroups.com ...
"raashid bhatt" <raashidbh...@gmail.comwrote in message

news:7c**********************************@t1g2000p ra.googlegroups.com...

#include< string.h>

#include< stdio.h>

#include< windows.h>
#include <string.h>
#include <stdio.h>
#include <windows.h>



< windows.his不是标准C头。请

省略此处发布的代码(无论如何都没有

与你的问题有关)。


<windows.his not a standard C header. Please
omit such from code posted here (it has nothing
to do with your question anyway).


int main(int argc,char * argv [])

{
int main(int argc, char *argv[])
{


char s [10] ="欢迎英寸;
char s[10] = "welcome";


char * p = s;

char ** prt = p; //错误发生在这里
char *p = s;
char **prt = p; //error happens here



那是因为你试图分配

一个不兼容的类型。 *写:


char ** prt =& p;


That''s because you''re trying to assign
an incompatible type. *Write:

char **prt = &p;


返回0;

}
return 0;
}



我已经向你展示了正确的语法。 *但是你想要做什么



-Mike


I''ve shown you correct syntax. *But what
exactly are you trying to do?

-Mike



这是错误的人为什么我需要& p作为p包含地址

this is wrong man why do i need &p as p consists the address


8月19日,15:01,raashid bhatt< raashidbh ... @ gmail.comwrote:
On 19 Aug, 15:01, raashid bhatt <raashidbh...@gmail.comwrote:

8月19日,6:54 * am,Mike Wahler < mkwah ... @ mkwahler.netwrote:


On Aug 19, 6:54*am, "Mike Wahler" <mkwah...@mkwahler.netwrote:



" raashid bhatt" < raashidbh ... @ gmail.comwrote in message
"raashid bhatt" <raashidbh...@gmail.comwrote in message


news:7c *************** ******************* @ t1g2000p ra.googlegroups.com ...
news:7c**********************************@t1g2000p ra.googlegroups.com...


#include< string.h>

#include< stdio.h>

#include< windows.h>
#include <string.h>
#include <stdio.h>
#include <windows.h>


< windows.his不是标准C头。请

省略此处发布的代码(无论如何都没有

来处理您的问题)。
<windows.his not a standard C header. Please
omit such from code posted here (it has nothing
to do with your question anyway).


int main(int argc,char * argv [])

{
int main(int argc, char *argv[])
{


char s [10] =" welcome" ;;
char s[10] = "welcome";


char * p = s;

char ** prt = p; //错误发生在这里
char *p = s;
char **prt = p; //error happens here


那是因为你试图分配

an不兼容的类型。 *写:
That''s because you''re trying to assign
an incompatible type. *Write:


char ** prt =& p;
char **prt = &p;


return 0;

}
return 0;
}


我已经向您展示了正确的语法。 *但是你确实想要做什么?

I''ve shown you correct syntax. *But what
exactly are you trying to do?


-Mike
-Mike



这是错误的人为什么我需要& p因为p包含地址
this is wrong man why do i need &p as p consists the address



没有它*不是*错误。考虑类型,p的类型为char *(p​​tr-to-

char)

prt的类型为char **(ptr-to -ptr-to-char)。它们不一样。

但是& p是ptr-to-char的地址所以它的类型为ptr-to-ptr-to-

char。

所以这项任务还可以。


获得一本好的教科书。并阅读它。

-

Nick Keighley


no it *isn''t* wrong. Consider the types, p has type char* (ptr-to-
char)
prt has type char** (ptr-to -ptr-to-char). They are not the same.
But &p is the address of a ptr-to-char so it has type ptr-to-ptr-to-
char.
So that assignment is ok.

Get a good text book. And read it.
--
Nick Keighley



这篇关于指针和数组。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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