关于“++、*、=”优先级的问题!
今天做《c和指针》的练习题,是关于倒置的,虽然没看答案自己也敲出来了,但是看完作者的代码,我就惊呆了,写了如此简练,但是里面有两句我是怎么也转不过弯来,来大神给我解释解释!1.temp = *str;
2.*str + + = *last_char;
3.last_char - - = temp;
“*”和“++”是一个优先级,
那为什么是赋完值地址在自增那。
我怎么那么别扭,不明白!
/* 自己动手丰衣足食,我琢磨出来了,放出来大家讨论一下 其实就是“前自增”和“后自增”的问题~!就这么简单,哎 脑袋有时候短路呀~! */ #include<stdio.h> int main(void) { char a[5] = "12345"; char *p; int i = 0; printf("\n"); p = a ; printf("a[0]%p\n",a[0]); printf("a[1]%p\n",a[1]); printf("a[2]%p\n",a[2]); printf("a[3]%p\n",a[3]); printf("a[4]%p\n",a[4]); printf("*************************************\n"); printf("char a[5] = “12345”\n"); printf("****《 p = a;》*****************\n"); printf("“p”所指向的值是:%c\n",*p); printf("“p”的指针地址是:%p\n",*a); printf("*************************************\n"); *p++ = 'A'; printf("******《*p++ = 'A';后》**************\n"); printf("*p值%c\n",*p); printf("*p地址%p指向a[1]\n",*p); printf("a[0]的值是:%c\n",a[0]); printf("a[0]的地址是: %p\n",a[0]); printf("**************************************\n"); *--p = 'Z'; printf("******《*--p = 'Z';后》**************\n"); printf("p所指向值是:%c\n",*p); printf("p的指针地址是:%p\n",*p); printf("a[0]的值是:%c\n",a[0]); printf("a[0]的地址是: %p\n",a[0]); printf("**************************************\n"); printf("a[0]%p\n",a[0]); printf("a[1]%p\n",a[1]); printf("a[2]%p\n",a[2]); printf("a[3]%p\n",a[3]); printf("a[4]%p\n",a[4]); return 0; }