0

I have this code:

typedef struct s1{ void *x; } s1; typedef struct s2{ unsigned char y[5]; } s2; s1 *s1_g; s2 *s2_g; 

What I wanted to do is to point pointer x to variable y.

I tried doing this:

s1_g->x = s2_g->y 

but receives a segmentation error

Anyone can please enlighten me?

2 Answers 2

1

If that's all of the code, then you haven't even initialized s1_g and s2_g. So dereferencing them will no doubt cause a segmentation error.

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

Comments

0

There should be a valid object at the pointer location. Since, there is no valid object at s1_g, behaviour is undefined on dereferencing them.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.