数组的访问

通过索引访问数组中的元素

1、 取出数组中的元素

2、 修改数组中的元素

3、 往数组中储存元素

格式:

数组名 [ 数组索引 ]

索引:每一个存储到数组的元素,都会自动的拥有一个编号,从0开始,这个自动编号称为数组索引(index)

注意:

1.直接打印数组名,打印的是数组的地址值

2.索引是从0开始,一直到"数组长度-1"   最大的索引是: 数组长度-1

3.动态方式创建数组,数组中的元素有默认值

整数类型的默认值都是 0

            浮点型的默认值是 0.0

            字符型的默认值是 ‘\u0000‘

            布尔型的默认值是  false

            引用数据类型的默认值是 null

4.静态方式创建数组,数组中的元素也有默认值,只不过一初始化就被覆盖了

数组的长度:  

数组名.length   返回的是数组长度,是一个int类型的值

原文地址:https://www.cnblogs.com/libinhong/p/10988761.html

时间: 2024-07-29 04:15:00

数组的访问的相关文章

数组形式访问对象

<?php//数组形式访问对对象/** * 1.通过继承PHP内置接口ArrayAccess来实现 * 2.必须实现方法:offsetExists,offsetGet,offsetSet,offsetUnset; */class NewObject implements ArrayAccess{    /**     * 检查一个偏移位置是否存在     * @param mixed $offset     * @return bool     */    public function off

数组式访问-ArrayAccess

以前对ArrayAccess不是很熟悉,现在整理下下有关ArrayAccess相关的知识,ArrayAccess接口就是提供像访问数组一样访问对象的能力的接口. 接口内容如下: ArrayAccess { //检查一个偏移位置是否存在 abstract public boolean offsetExists ( mixed $offset ); //获取一个偏移位置的值 abstract public mixed offsetGet ( mixed $offset ); //设置一个偏移位置的值

C# 类如何声明索引器以提供对类的类似数组的访问的代码

研发期间,将内容过程中比较常用的内容段做个收藏,如下内容内容是关于 C# 类如何声明索引器以提供对类的类似数组的访问.的内容,希望能对各位有用处. using System;using System.IO; public class FileByteArray{ public FileByteArray(string fileName) { stream = new FileStream(fileName, FileMode.Open); } public void Close() { stre

javascript对象属性和数组的访问

javascript对象属性的访问 假如有对象test:var test = {  "a":1,  "b":2};直接访问对象test的属性a的值,有两种方法: 1.test.a; 2.test["a"];   (注意这里要用引号) 但若是用for/in语句访问对象的属性值,则必须用“[]”运算符啦:    for(m in test){        alert(test[m]);        alert(test.m);   //这里会弹出

数组的访问形式

/********将数组data[N]中所有元素求和****************/ #define N 10 int data[N],sum,*pData; for(pData=&data[0];pData<&data[N];pData++) { sum+=*pData; } //以上for语句等价于 for(int i=0;i<N;i++) { sum+=Data[i]; }  

PHP预定义接口中 ArrayAccess 数组式访问接口

<?php class obj implements arrayaccess { private $container = array(); public function __construct () { $this -> container = array( "one" => 1 , "two" => 2 , "three" => 3 , ); } public function offsetSet ( $off

ArrayAccess(数组式访问)接口

接口摘要  ArrayAccess { /* 方法 */ abstract public boolean offsetExists ( mixed $offset ) abstract public mixed offsetGet ( mixed $offset ) abstract public void offsetSet ( mixed $offset , mixed $value ) abstract public void offsetUnset ( mixed $offset ) }

php 以数组形式访问对象

官方文档上: ArrayAccess { /* Methods */ abstract public boolean offsetExists ( mixed $offset ) abstract public mixed offsetGet ( mixed $offset ) abstract public void offsetSet ( mixed $offset , mixed $value ) abstract public void offsetUnset ( mixed $offs

perl访问数组中参数

数组一个是存储标量值的无序列表变量. 数组变量以 @ 开头.访问数组元素使用 $ + 变量名称 + [索引值] 格式来读取,实例如下: #!/usr/bin/perl @names = ("google", "runoob", "taobao"); print "\$names[0] = $names[0]\n"; #$names[0] = google 用变量接收数组及访问: my $list = get_list();/*