zoukankan      html  css  js  c++  java
  • 2016.5.17——数组的定义

    数组的定义

    学到的:

    1.数组如何定义:

      主要有两种:

            数组:int a[5]; int a[]={1,2,3} 数组型时要有大小和内容至少一个。

            指针:*a 指向数组的第一个元素的地址 如何创建动态数组:int *a; a = new int[n]; 或者 int *a = new int[n];注意数组的定义。上一篇文章中有定义。

     1 // array-in-out.cpp : 定义控制台应用程序的入口点。
     2 //
     3 
     4 #include "stdafx.h"
     5 #include "iostream";
     6 using namespace std;
     7 
     8 int _tmain(int argc, _TCHAR* argv[])
     9 {
    10     const int N = 8;
    11     int first[N] = { 1, 2, 3, 4, 5, 6, 7, 8 };
    12     int *second = first;
    13 //    int *second = &first[0];    //此处指向的是first的第一个元素的地址
    14 
    15     cout << first << endl;    //输出第一个元素的地址
    16     cout << second << endl;    //输出第一个元素的地址
    17     cout << &second[1] << endl;    //输出第二个元素的地址
    18 
    19     cout << "this number arrary is :
    ";
    20     for (int i = 0; i < N; i++)
    21     {
    22         cout << second[i];
    23     }
    24     cout << endl;
    25     system("pause");
    26     return 0;
    27 }

      运行结果:

      

      

      first = &first[0]= address of first element of array

      且地址是随机的,每次都不同

  • 相关阅读:
    django-templates 模板变量
    实用代码
    游戏渠道后台上线
    游戏投放中的-LTV概念与价值
    转字符串格式format技巧
    mysql -数据库设计三范式
    OAuth2.0基本原理及应用
    回调函数
    GitHub 博客园快捷发布工具
    前端react antd加载错误解决
  • 原文地址:https://www.cnblogs.com/zhuzhu2016/p/5506506.html
Copyright © 2011-2022 走看看