F. Picazo - 2 months ago 12

C Question

I have a small segment of C code that I am a bit confused about.

`int *p, *q, arr[4]={5,8,3,7}`

p = q = arr;

Does the pointer assignment mean both

`p`

`q`

`arr`

`p`

`q`

`arr`

Answer

The assignment operator (`=`

) is right associative. This means

```
a = b = c;
```

parses as

```
a = (b = c);
```

That is, the value of `c`

is assigned to `b`

, and the result value of this assignment operation is assigned to `a`

.

The `=`

operator is defined to return the value that was assigned, so this effectively sets both `a`

and `b`

to `c`

.