指向运算符会移动指针吗?

来源:互联网 发布:excel表格内换行 mac 编辑:程序博客网 时间:2024/05/24 05:41

不会。
如果p指向一个结构体变量stu,以下三种用法等价:
1. stu.成员名stu.num
2. (*p).成员名(*p).num
3. p->成员名p->num

(*p).name 等价于 p->name "->"称为指向运算符

所以指向运算符不会移动指针。

可进行如下试验

    include <stdio.h>    int main() {    struct Student{        char name[20];        int num;    }student;    student.num=100;    Student *p;    p=&student;    printf("%d\n",student.num);    printf("%d\n",(*p).num);    printf("p:%d\n",p);//初始位置    printf("%d\n",p->num);    printf("p:%d\n",p);//使用指向运算符后的位置    return 0;}

结果如下:
100
100
p:2686724
100
p:2686724

0 0