[讲课]2-13 函数的参数及返回值
来源:互联网 发布:双子星mac版 编辑:程序博客网 时间:2024/05/18 00:04
1. 一个函数必须有名字、形参、返回值三个要素。
- main函数可以调用其他方法。
public class A {static int f(int x, int y){int k = x + y;return k;} public static void main(String[] args){ int a = 10; int b = 20; int x = f(a, b); System.out.println(x); }}返回30。
2. 形参也是一种局部变量。
- 形参在定义时并不申请,而是在调用时分配。
- 形参分配后,将实参拷贝到形参中。
- 之后,执行函数代码块。
- 返回时,先清除调用时分配的变量。
3. 栈能够使机器状态能够沿着原路返回。
4. 形参变化不影响实参。
public class A { static int f(int x, int y){x++;System.out.println("x=" + x);int k = x + y;return k;} public static void main(String[] args){ int a = 10; int b = 20; f(a, b); System.out.println(a); }}
输出
x=11
10。
0 0
- [讲课]2-13 函数的参数及返回值
- 函数参数及返回值
- C++函数的参数传递、返回值及函数声明
- js 函数作为参数及返回值的例子
- js 函数作为参数及返回值的例子
- open函数参数及返回值
- open函数参数及返回值
- open函数参数及返回值
- open函数参数及返回值
- open函数参数及返回值
- [讲课]2-8 串的基本用法
- [讲课]2-12 局部变量的特性
- 基础知识—函数-函数参数及返回值
- [讲课]2-7 布尔型
- [讲课]2-9 表达式
- [讲课]2-10 流程控制
- Windows API的参数及返回值
- main函数的参数与返回值
- 《JavaScript高级程序设计 第三版》学习笔记 (八)块作用域及私有成员
- 成为Android高手的路径
- [Android] 为Android安装BusyBox —— 完整的bash shell
- Android手机抓包分析协议
- Codeforces Round #256 (Div. 2)E(DFS暴搜)
- [讲课]2-13 函数的参数及返回值
- spring中的ResourceBundleMessageSource复习
- Eclipse中安装Hibernate插件
- CSS中的Cursor属性的应用
- 深入浅出java并发
- Java中只有按值传递,没有按引用传递!
- Eclipse中安装Spring插件
- POJ2411(状态压缩DP)
- 触摸控制移动与缩放算法 - Cocos2d-JS + CocosBuilder