Array and pointor

 

int ia[]={ 0, 1, 2, 3, 4, 5};

for(size_t i=0;i!= 6;i++)

cout<<ia[i];

 

 

 

 ----------------------------------------------------------------------------------------------------------

int ival=1024,ival2=2048;

int *pi=&ival, *pi2=&ival2;

pi=pi2;

 

cout<<ival<<"/r/n";

cout<<ival2<<"/r/n";

cout<<*pi<<"/r/n";

cout<<*pi2<<"/r/n";

 

ival=1024,ival2=2048;

int &ri=ival, &ri2=ival2;

ri=ri2;

 

cout<<ival<<"/r/n";

cout<<ival2<<"/r/n";

cout<<ri<<"/r/n";

cout<<ri2<<"/r/n";

----------------------------------------------------------------------------------------------------------

Console result: 

----------------------------------------------------------------------------------------------------------

1024

2048

2048

2048

2048

2048

2048

2048

----------------------------------------------------------------------------------------------------------

 

int ival=1024;

int *pi=&ival;

int **ppi=&pi;

 

cout<<ival<<"/r/n";

cout<<*pi<<"/r/n";

cout<<**ppi<<"/r/n";

----------------------------------------------------------------------------------------------------------

Console result: 

----------------------------------------------------------------------------------------------------------

1024

1024

1024

----------------------------------------------------------------------------------------------------------

 

const pointer point to  a const value

----------------------------------------------------------------------------------------------------------

 

const double pi=3.14;

const double *cptr=&pi;

double dval=3.14;

 

////*cptr=&dval; //error: *cptr might be const

cptr=&dval;//ok:but cannot change dval through cptr

dval=3.14159;

cout<<*cptr<<"/r/n";

cout<<dval<<"/r/n";

 

double *ptr=&dval;

*ptr=2.72;

cout<<*cptr<<"/r/n";

cout<<dval<<"/r/n";

----------------------------------------------------------------------------------------------------------

Console result: 

----------------------------------------------------------------------------------------------------------

3.14159

3.14159

2.72

2.72

----------------------------------------------------------------------------------------------------------

 

 

typedef string *pstring;

const pstring cstr;

<==>

string *const cstr;

 

c style: #include  <string.h>

c++ style: #include <cstring>

 

 

typedef int int_array[3];

int_array *ip=ia;

 

For(int_array *p = ia; o != ia+3; ++p)

{

   for(int *q = *p; q != *p+4;++q)

  {

         cout<<*q;

  }

}

----------------------------------------------------------------------------------------------------------

 

 

Terminology:

c-style string

Compiler extension

Compound type

Const void*

Delete expression

dimension

Dynamically allocated

Free store

heap

New expression

pointer

Pointer arithmetic

precedence

ptrdiff_t

Size_t

*opertator

++operator

[]operator

&operator

void*

时间: 2024-10-11 04:16:09

Array and pointor的相关文章

PHP数组的交集array

返回一个交集共有元素的数组(只是数组值得比较).array_intersect_assoc()函数是将键值和值绑定,一起比较交集部分.array_intersect_key()函数是将两个数组的键值进行比较,返回键值交集的数组.但实际应用中也遇到了一些小问题,正如下: 实例: 复制代码 代码如下: <?PHP $array = array("red"=>"Red","green"=>"red4","

如何学习PHP array

 定义和用法 array_fill() 函数用给定的值填充数组,返回的数组有 number 个元素,值为 value.返回的数组使用数字索引,从 start 位置开始并递增.如果 number 为 0 或小于 0,就会出错. 语法 array_fill(start,number,value)   参数 描述   start必需.数值,规定键的起始索引. number必需.数值,规定填充的数量,其值必须大于 0. value必需.规定要插入的值.     例子 <?php $a=array_fil

numbers-如何让用户输入一个数字,然后分辨是比array里面的数字大还是小

问题描述 如何让用户输入一个数字,然后分辨是比array里面的数字大还是小 import java.util.Scanner; public class Arrays13 { public static void main(String[] args) { Scanner reader = new Scanner(System.in); int number; int[] numbersArray = new int[]{11,8,4,9,22,30,24,23,35,0}; System.ou

JavaScript Array对象介绍

Array 数组 1. 介绍       数组是值的有序集合.每个值叫做一个元素,而每个元素在数组中有一个位置,以数字表示,称为索引.JavaScript数组是无类型:数组元素可以是任意类型,并且同一个数组中的不同元素也可能有不同的类型. --<JavaScript权威指南(第六版)> 2. 定义 var names = new Array("张三", "李四", "王五"); //或者 var names = ["张三&q

[华为机试练习题]29.Arrange an Array to Form a Smallest Digit

题目 描述: Question: Input an array of positive integers, arrange the integers to form new digits, and output the smallest digit among all the new ones. Input Example 1: {2, 1} Output Example 1: 12 Input Example 2: {32, 321} Output Example 2: 32132 Input

Dojo学习笔记5. dojo.lang.array &amp;amp; dojo.lang.func &amp;amp; dojo.string.extras

模块:dojo.lang.array dojo.lang.has 判断对象是否具有指定属性,不过这个方法有用吗,不如直接使用 if(name in obj) Usage Example: dojo.lang.has(dojo.lang, "has"); //will return true dojo.lang.isEmpty 判断对象或数组是否为空 Usage Example: dojo.lang.isEmpty({a: 1}); //will return false dojo.la

removing objects from an array

I am creating a program that uses an array of objects declared with Element* elements =newElement[number]; where an element is a class that has/needs a its own destructor. when I go to delete this would I use just use array delete, and have the progr

用reverse方法将Javascript数组(Array)对象内容反转的示例

<script type="text/javascript">var a,aa;a = new Array(2,4,6,8,10);aa = a.reverse();document.write (aa);</script> 该Javascript解释:这个示例用到了Javascript数组(Array)的reverse方法,该方法能将数组的内容反转.该示例中,首先声明了两个变量a和aa:然后定义a为数组,并赋值给a:然后用reverse方法将数组a的内容反转,

java中List、Array、Map、Set等集合相互转换的最佳方法

     在java中,我们经常需要对List.Array等做一些转换操作,当然转换方法有很多种,但哪种方法既方便又高效呢?在这里向大家介绍一下集合间的最佳转换方法. 1.List转换为Array List<String> list = new ArrayList<String>(); list.add("China"); list.add("Switzerland"); list.add("Italy"); list.a