CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  新手乐园

请高手破解决这段代码哦

楼主BlackWhiteforest(黑白森林)2004-08-01 11:47:17 在 C/C++ / 新手乐园 提问

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

相关问题

  • 请教一段代码
  • 请看这一段代码!
  • 请教一段代码
  • 请看一段代码
  • 请教一段代码:)
  • 代码片段请教:
  • 请看这段代码?
  • 请看这段代码!!!!
  • 请看这段代码!
  • 请给出一段代码

关键词

  • 内存
  • grades
  • 数组
  • allocated memory
  • slocker room
  • visitor
  • reference
  • 例子
  • similar
  • assigning

得分解答快速导航

  • 帖主:BlackWhiteforest
  • arden1019
  • kaphoon

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo