Chinaunix

标题: 结构体指针问题 [打印本页]

作者: ge_yong_linux    时间: 2011-07-16 12:19
标题: 结构体指针问题
第一个
#include<stdio.h>
#include<string.h>
main()
{
struct student
        {.
         .
         .
        }

struct student stu_1;
struct student *p;
p=&stu_1;/*这里是p=&stu_1*/       
        .       
        .
        .
}
第二个
#include<stdio.h>
struct student
          {.
         .
         .
        }
struct student stup[3]={{...},
                        {...},
                        {...}};
main()
{
struct student *p;
for(p=stu;p<stu+3;p++)/*这里是p=stu*/
...;
}

同样是结构体指针为什么一个要用&一个不能用么,(这两个例子中的第一个&去掉编译不通过。第二个加个&编译不通过)。为什么呢?
作者: hellioncu    时间: 2011-07-16 14:48
第二个是stup吧,是数组
作者: xhaisherry    时间: 2011-07-16 14:59
第一个是结构体,相当于一种类型。

第二个是结构体数组,数组本身就是指针,所以不用&
作者: ge_yong_linux    时间: 2011-07-16 16:24
回复 3# xhaisherry


    谢谢了!
作者: ge_yong_linux    时间: 2011-07-16 16:25
回复 2# hellioncu


    没写错啊,就是stu
作者: ccj507    时间: 2011-09-06 16:56
回复  hellioncu


    没写错啊,就是stu
ge_yong_linux 发表于 2011-07-16 16:25



    应该是写错了, 要么就是定义的时候多写了一个p...
    楼主仔细看看
作者: snowboy9859    时间: 2011-09-10 15:00
回复 1# ge_yong_linux


    1.变量 2.数组




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2