赞
踩
需要结合优先级进行分析,注意结合方向
假如 * p = 2;那么执行 b=*p++; 结果 b=2。因为 b=*p++ 相当于 b=*p; p++。即 p 是“先使用,后自增”。
#include<stdio.h>
int main(int argc, const char *argv[])
{
int b,a[2] ={ 2,4};
int *p = NULL;
p = a;
b = *p++;
printf("b=%d *p = %d\n",b,*p);
return 0;
}
输出:
假如 * p = 2;如果执行 b= * ++p; 结果 b=4。因为 b=*++p 相当于 p++; b=*p。即 p 是“先自增,后使用”。
#include<stdio.h>
int main(int argc, const char *argv[])
{
int b,a[2] ={ 2,4};
int *p = NULL;
p = a;
b = *++p;
printf("b=%d *p = %d\n",b,*p);
return 0;
}
输出:
假如 * p = 2;如果执行 b= ( * p)++; 结果 b=2。因为 b=(*p)++相当于 先 b=*p; *p= *p+1。
#include<stdio.h>
int main(int argc, const char *argv[])
{
int b,a[2] ={ 2,4};
int *p = NULL;
p = a;
b = (*p)++;
printf("b=%d *p = %d\n",b,*p);
return 0;
}
输出:
假如 * p = 2;如果执行 b=++(*p); 结果 b=3。因为 b=++(*p)相当于 先 *p = *p+1; b = *p;
#include<stdio.h>
int main(int argc, const char *argv[])
{
int b,a[2] ={ 2,4};
int *p = NULL;
p = a;
b = ++(*p);
printf("b=%d *p = %d\n",b,*p);
return 0;
}
输出:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。