在进行弹栈的时候为什么不传e的地址不行
void pop(stack* s,elemtype* e) //这里e接受地址为什么不行{
if(s->top==s->base)
return;
*e=*--(s->top);
} 在交换两个变量的时候为什么不传a和b的地址不行?
#include <stdio.h>
void SwapA(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void SwapB(int a, int b)
{
int temp = a;
a = b;
b = temp;
}
int main(void)
{
int a = 100;
int b = 0;
SwapA(&a, &b);
SwapB(a, b);
printf("%d %d\n", a, b);
return 0;
}
因为C的函数是是按值传递
页:
[1]