指针指针。 [英] Pointers pointers.

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

问题描述

我以为我可以将一个字符数组分配给一个指向指针的指针。

然而,当我这样做时,

以下内容:


#include< stdio.h>


int main(void){

char buff [] =" test";

char ** output =& buff;


返回0;

}


我得到:

$ gcc -g ptr.c -o ptr

ptr.c:函数`main'':

ptr .c:5:警告:从不兼容的指针类型初始化


我在这里做错了什么?


Chad

I thought I could assign an array of chars to a pointer to pointer.
However, when I do
the following:

#include <stdio.h>

int main(void) {
char buff[] ="test";
char **output = &buff;

return 0;
}

I get:
$gcc -g ptr.c -o ptr
ptr.c: In function `main'':
ptr.c:5: warning: initialization from incompatible pointer type

What am I doing wrong here?

Chad

推荐答案

gcc -g ptr.c -o ptr

ptr.c:在函数`main'':

ptr.c:5:警告:从不兼容的指针类型初始化


我在这里做错了什么?


Chad

gcc -g ptr.c -o ptr
ptr.c: In function `main'':
ptr.c:5: warning: initialization from incompatible pointer type

What am I doing wrong here?

Chad


Chad写道:
Chad wrote:

我以为我可以为指针分配一个字符数组指针。

但是,当我这样做时,


#include< stdio.h>


int main(无效){

char buff [] =" test";

char ** output =& buff;


返回0;

}


我得到:
I thought I could assign an array of chars to a pointer to pointer.
However, when I do
the following:

#include <stdio.h>

int main(void) {
char buff[] ="test";
char **output = &buff;

return 0;
}

I get:

gcc -g ptr.c -o ptr

ptr.c:在函数`main''中:

ptr.c:5:警告:从初始化开始不兼容的指针类型
gcc -g ptr.c -o ptr
ptr.c: In function `main'':
ptr.c:5: warning: initialization from incompatible pointer type



char [5]的地址不是char **,它是char(*)[5];

char(*输出)[5] =& buff;

The address of a char[5] is not a char **, it is a char (*)[5];
char (*output)[5] = &buff;


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

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