Why do I get "Value computed is not used" when working with pointers?
摘自:http://tigcc.ticalc.org/doc/faq.html#99
Q: I have a variable and a pointer to it, for example,
int a, ptr_to_a = &a;
When I tried to modify the variable "a" indirectly using the pointer, like in
*ptr_to_a++;
the compiler reports to me "Value computed is not used". What is wrong here?
*(ptr_to_a++);
i.e. it increases the pointer, then reads the value from it (which is not used for anything). This is not what do you want, of course. To perform what do you want (i.e. to increase the variable pointed to by the pointer), use parentheses to change the order of evaluation, i.e. use
(*ptr_to_a)++;
This will work as expected.