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 好听的元旦简短祝福语