请高手破解决这段代码哦
The solution in Java is to allocate memory at runtime. Programmers call this dynamically allocating memory. You dynamically allocate memory by using the new operator when declaring the array, as shown here:
int grades[] = new int[10];
This example looks a little strange, but it creates the same array as is created in the previous example. There are three things happening in this statement.
First, the new operator tells the computer to reserve 10 array elements, each the size of an int data type. The new operator returns a reference to the allocated memory.
Next, a reference to an int data type called grades is declared (int grades[]).
Last, the reference to the memory allocation returned by the new operator is assigned to the reference declared in the program.
This can be confusing even for experienced programmers to understand. If you’re confused, remember this visitor’s locker room example: a stadium has a locker room with “Visitors” on the door. This is similar to the reference grades[]. The visitor’s locker room refers to the visiting team similar to the way grades[] refers to allocated memory: each game brings in a different visiting team who is assigned to the visitor’s locker room. This is similar to assigning allocated memory to the reference grades[].
小弟弟很菜的看不明白哦 请高手帮帮忙哦 谢谢了!
问题点数:20、回复次数:3Top
1 楼arden1019(CSCUM)回复于 2004-08-01 12:43:07 得分 15
这段话是这个意思(大概):
java使用运行时分配内存,程序员叫它动态内存分配,你可以使用new操作符像下面语句声明一个数组:
int grades[] = new int[10];
这个例子看起来有些奇怪,但是它确实创建了和前面例子一样的数组。这条语句导致了下面三家事情发生:
1 new操作符在内存中创建了一个10*size(int)大小的空间,并返回它的引用。
2 一个int类型数组被声明
3 上面两个建立联系
这可能对老程序员带来困惑,当你困惑时请想象下 衣帽间的例子:
在一个体育场有门上写着来访者的衣帽间.......下面就别说了可以吗?
Top
2 楼kaphoon(齐柏林飞艇)回复于 2004-08-01 13:53:40 得分 5
1.把java的东西发在C/C++版,什么意思啊
2.java中不需要内存手动回收,所以不要delete
3.这个式子也不是标准写法
int[] grades = new int[10];Top
3 楼BlackWhiteforest(黑白森林)回复于 2004-08-01 14:56:54 得分 0
对不起 大哥 我是刚刚才下的数据结构 谁知道是JAVA?。。实在对不起哦!Top




