[問題]傳遞結構位址
#include <stdio.h>
#include <stdlib.h>
struct student
{
int id;
char name[10];
};
void sumfunc(struct student *);
int main(int argc, char *argv[])
{
struct student stu={5,"okok"};
printf("%d\n",stu.id);
sumfunc(&stu);
printf("%d\n",stu.id);
//puts(++ptr);
system("PAUSE");
return 0;
}
void sumfunc(struct student *ptr)
{
*ptr=10; // <<我的問題點
}
想利用函數將ID值改為10
我的問題點這樣寫為什麼不能編譯
修改成
ptr->id=10;
ptr+1->name="koko"; <<則此行不能編譯
感謝大家的回答
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 120.126.10.54
推
05/15 23:09, , 1F
05/15 23:09, 1F
推
05/16 00:00, , 2F
05/16 00:00, 2F
→
05/16 10:45, , 3F
05/16 10:45, 3F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章