c语言作业(*p &n)用法
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/16 17:21:31
c语言作业(*p &n)用法
1.Study the following section of C code:int n1 = 2,n2 = 5,n3[ ] = {3,4,5,6,7};int* p1 = &n1;int * p2 = n3;*p2 = (*p1)++ + *(p2) ; p2 = &n3[3];n1 = *p1 + *(p2) + *(&n2); p1 = &n3[4];What are the values of *p1,*p2,n1,n2 and n3 after the last statement?(25 points)*p1=7,*p2=6,n1=14,n2=5,n3[]=[5,4,5,6,7]
1.Study the following section of C code:int n1 = 2,n2 = 5,n3[ ] = {3,4,5,6,7};int* p1 = &n1;int * p2 = n3;*p2 = (*p1)++ + *(p2) ; p2 = &n3[3];n1 = *p1 + *(p2) + *(&n2); p1 = &n3[4];What are the values of *p1,*p2,n1,n2 and n3 after the last statement?(25 points)*p1=7,*p2=6,n1=14,n2=5,n3[]=[5,4,5,6,7]
int n1 = 2,n2 = 5,n3[ ] = {3,4,5,6,7};
int *p1 = &n1; // 这使 *p1=2
int *p2 = n3; // 这使p2指向 n3[0],*p2=3
*p2 = (*p1)++ + *(p2) ;
// 注意后坠加,表达式里用原来的值,出表达式后自增1
// 所以 *p2=2+3=5; 出表达式后 *p1=2+1=3;
// 由于 p2指向 n3[0],所以 n3[0]=5; 新值5!
p2 = &n3[3]; // p2指向 n3[3],它的值 *p2=6
n1 = *p1 + *(p2) + *(&n2); // *(&n2) 就是n2=5,n1=3+6+5 =14
p1 = &n3[4]; // *p1=7
printf("%d %d %d %d\n",*p1,*p2,n1,n2);
当前 值:7 6 14 5
n3[]=[新值5,老值 4,5,6,7];
int *p1 = &n1; // 这使 *p1=2
int *p2 = n3; // 这使p2指向 n3[0],*p2=3
*p2 = (*p1)++ + *(p2) ;
// 注意后坠加,表达式里用原来的值,出表达式后自增1
// 所以 *p2=2+3=5; 出表达式后 *p1=2+1=3;
// 由于 p2指向 n3[0],所以 n3[0]=5; 新值5!
p2 = &n3[3]; // p2指向 n3[3],它的值 *p2=6
n1 = *p1 + *(p2) + *(&n2); // *(&n2) 就是n2=5,n1=3+6+5 =14
p1 = &n3[4]; // *p1=7
printf("%d %d %d %d\n",*p1,*p2,n1,n2);
当前 值:7 6 14 5
n3[]=[新值5,老值 4,5,6,7];