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 生日广州男生祝福语简短