C语言中的空指针数组 [英] Array of void pointers in C

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

问题描述

我想创建一个空指针数组.

I would like to create arrays of void pointers.

# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>

int main(){

void * A[3];
void * D[3];
void * F[2];
void * G[4];
void * H[4];
void * J[3];
void * K[5];
void * L[4];
void * M[5];


A={D, H, K};
D ={A, G, H};
F ={K, L};
G={D, H, J, M};
H={A, G, L, M};
J={G, L, M};
K={A, F, H, L, M};
L={F, J, K, M};
M={G, H, J, K, L};
return 0;
}

问题是代码无法编译,它说:"{令牌之前的预期表达式"

The problem is the code won't compile it says: "expected expression before { token"

怎么了? 我使用这些指针是因为它们的值无关紧要,我只希望它们指向彼此.例如,M必须指向G,H,J,K和L.

What is wrong? I am using these pointers because their value doesn't matter I just want them to point to each other. For example M has to point to G, H, J, K and L.

非常感谢您的帮助或建议,

Thank you very much for any help or advice,

推荐答案

如果要使用该表示法,则必须在同一行上进行.在您的情况下,您必须这样做

You have to do it on the same line if you want to use that notation. In your case you would have to do

A[0] = D;
A[1] = H;
A[2] = K;

之所以如此,是因为您需要在此时尚未解析的符号上添加void *.

and so on because you need to add void * to symbols that havent been resolved at that point yet.

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

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