Why doesn't the compiler report a missing semicolon?

后端 未结 5 1003
夕颜
夕颜 2020-12-13 16:55

I have this simple program:

#include 

struct S
{
    int i;
};

void swap(struct S *a, struct S *b)
{
    struct S temp;
    temp = *a    /*          


        
5条回答
  •  粉色の甜心
    2020-12-13 17:27

    Some good answers above, but I will elaborate.

    temp = *a *a = *b;
    

    This is actually a case of x = y = z; where both x and y are assigned the value of z.

    What you are saying is the contents of address (a times a) become equal to the contents of b, as does temp.

    In short, *a *a = is a valid statement. As previously pointed out, the first * dereferences a pointer, while the second multiplies two values.

提交回复
热议问题