引用即是别名

看一下程序

#include <stdio.h>

typedef unsigned long int UINT4;

typedef struct {
UINT4 state[4];
UINT4 count[2];

} MY_T;

void initByPoint (MY_T *context)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
*/
context->state[0] = 1;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
}
void initByRef (MY_T &context)
{
context.count[0] = context.count[1] = 0;
/* Load magic initialization constants.
*/
context.state[0] = 2;
context.state[1] = 0xefcdab89;
context.state[2] = 0x98badcfe;
context.state[3] = 0x10325476;
}

void initByCommon (MY_T context)
{
context.count[0] = context.count[1] = 0;
/* Load magic initialization constants.
*/
context.state[0] = 3;
context.state[1] = 0xefcdab89;
context.state[2] = 0x98badcfe;
context.state[3] = 0x10325476;
}
int main(){

MY_T t;
MY_T &r=t;
printf("t.state[0]=%lu\n",t.state[0]);
printf("r.state[0]=%lu\n",r.state[0]);
initByCommon(t);
//initByCommon(r); 结果一样
printf("t.state[0]=%lu\n",t.state[0]);
printf("r.state[0]=%lu\n",r.state[0]);
initByPoint(&t);
//initByPoint(&r);结果一样
printf("t.state[0]=%lu\n",t.state[0]);
printf("r.state[0]=%lu\n",r.state[0]);
initByRef(t);
//initByRef(r); 结果一样
printf("t.state[0]=%lu\n",t.state[0]);
printf("r.state[0]=%lu\n",r.state[0]);





return 1;
}


t.state[0]=3218421528
r.state[0]=3218421528
t.state[0]=3218421528
r.state[0]=3218421528
t.state[0]=1
r.state[0]=1
t.state[0]=2
r.state[0]=2


elemtype& a1;
elemtype *a2;
elemtype a3;

fun1(elemtype& a);
fun2(elemtype *a);
fun3(elemtype a);

请问a1,a2,a3分别能做为fun1,fun2,fun3中哪几个函数的参数?

a1-f1,f3
a2-f2
a3-f1,f3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值