Muhammet Hurma
Muhammet Hurma

Reputation: 19

in c, what does mean sizeof()..[-1]

I am trying to understand the code piece below But I could not solve it,(especially )

void fun(char **p)
{
  char *t;
  t = (p+= sizeof(int))[-1]; //especially this line,why there is "-1" in here?
  printf("%s\n", t);
}

thanks for your time.

Upvotes: 1

Views: 176

Answers (1)

NPE
NPE

Reputation: 500327

The

t = (p+= sizeof(int))[-1];

can be rewritten as

p += sizeof(int); /* The logic of this doesn't make a whole lot of sense to me */
t = *(p - 1);

Hope this clears things up.

Upvotes: 5

Related Questions