C语言中什么是按值调用?
按值传递或按值调用作为参数发送。
算法
请参阅按值调用的算法。
Step 1: Enter any 2 numbers at runtime
Step 2: Read those two numbers from console
Step 3: Call the function swap with arguments is a call by value
Step 4: Go to called function
swap(int a,int b)
Step 5: Print the numbers after swap示例
以下是按值调用的C程序-
#include<stdio.h>
void main(){
void swap(int,int);
int a,b;
clrscr();
printf("enter 2 numbers");
scanf("%d%d",&a,&b);
printf("Before swapping a=%d b=%d",a,b);
swap(a,b);
printf("after swapping a=%d, b=%d",a,b);
getch();
}
void swap(int a,int b){
int t;
t=a;
a=b;
b=t;
}输出结果执行上述程序时,会产生以下结果-
enter 2 numbers 10 20 Before swapping a=10 b=20 After swapping a=10 b=20
作者头像
作者名称
作者性别



评论列表