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输出结果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
热门推荐
10 特别的端午祝福语简短
11 对女友的简短祝福语
12 六一祝福语简短感动女生
13 生日宝宝祝福语简短独特
14 老师对学校祝福语简短
15 分别祝福语简短情侣短句
16 双节祝福语简短唯美
17 参加儿子大学祝福语简短
18 对离岗同事祝福语简短