&
演算子をつけることは、
通常の変数の場合と同じである。
先の例で、誕生年を関数内部で修正し、呼び出し側へ反映させるには、
次のようにすればよい。
#include ”psrec2.h” |
#include <stdio.h> |
void main(){ |
psrec2 student; |
student.birthday.yy = 1968; |
student.birthday.mm = 4; |
student.birthday.dd = 6; |
printf(”birthday before call func is %d %d %d \n”, |
student.birthday.yy, student.birthday.mm, student.birthday.dd); |
func(&student); |
printf(”birthday after call func is %d %d %d \n”, |
student.birthday.yy, student.birthday.mm, student.birthday.dd); |
} |
void func(psrec2 *student){ |
student->birthday.yy = 2000; |
student->birthday.mm = 1; |
student->birthday.dd = 1; |
} |
上記を実行すると、画面には次のように出力され、 関数内部での修正が呼び出し側に反映されることが確認できる。
birthday before call func is 1968 4 6 |
birthday after call func is 2000 1 1 |