2

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"

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,

4 Answers 4

6

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;

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

Sign up to request clarification or add additional context in comments.

Comments

4

This is the way C works.

I believe you want code that looks like this:

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

or code that looks like this:

void * A[3]={D,H,K};

Comments

2

You can't use array initializers as assignments. You'll need to do the assignments element wise:

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

1 Comment

It would be helpful to point out that although D, H and K are arrays, they automatically decay to a pointer when used on the right side of an assignment.
2

Arrays are not allowed on the left side of an assignment except when declared, and array initializers could be used only during declarations as well.

So you would have to write for example:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.