|
发表于 2008-7-24 10:54:26
|
显示全部楼层
楼主只要考虑这样一个问题就可以了
- struct T {
- int x, y;
- };
- struct T a, b;
- a = b;
复制代码
楼主认为这是否合乎语法呢?
再考虑一个问题
- struct T {
- int x, y;
- };
- void fn1(struct T a)
- {
- printf("%d\n", a.x);
- }
- void fn2(struct T * p)
- {
- printf("%d\n", p->x);
- }
复制代码
一般都会建议使用 fn2 的形式, 而不是 fn1, 楼主想想这是为什么?
最后再想一想, 下面的例子中, fn1 和 fn2 是否能够达到预期的效果, 为什么?
- struct T {
- int x, y;
- };
- void fn1(struct T a)
- {
- a.x = 0;
- }
- void fn2(struct T * p)
- {
- p->x = 0;
- }
复制代码 |
|