(1)java 数组属于引用类型,放在堆空间
public class Var {
public static void main(String args[]) {
int a = 3;
float f = (float)3.14; //强制转换
float f2 = 3.14f;
int i = 4;
short s = 4;
short s2 = (short)40000; // 超过short类型,强制转换
//s = i;
s = (short)(s + 1);
s = (short)(s + s2);
/* Java has no pointer */
//int* p = malloc(10*sizeof(int));
int p[] = new int[10];
int p2[] = {1,2,4}; /* static alloc */
//char str[100];
char str[] = new char[100];
//char str2[] = "abc";
String str2 = "abc";
p = null;
p2 = null;
str = null;
str2 = null;
}
}
public class Param {
public static void main(String args[]) {
int x = 1;
fun (x); // 1
int p[] = new int[1];
p[0] = 123;
System.out.println("Before fun2: "+p[0]);
fun2(p);
System.out.println("After fun2: "+p[0]); //200
System.out.println(x);
}
public static void fun(int x) {
x = 100;
}
public static void fun2(int[] p) {
p[0] = 200;
}
}