zoukankan      html  css  js  c++  java
  • [ASM C/C++] C语言数组

    固定长度的数组:

      可以具有任何的存储类别。

    长度可变的数组:

      只能具有自动的生存周期(定义于语句块内,眀没有static修饰符)。

      名字必须为一般的标识符,因此结构或联合的成员不能是数组的标识符。

    读写数组数据可按索引和指针两种方法。

    #include <stdio.h>
    
    
    int a[10];        //具有外部链接
    static int b[10]; //具有静态的生存周期和作用域
    
    
    void parray(int count, int arr[])
    {
        //索引访问
        for(int i=0; i<count; i++)
        {
            printf("the %d is: %d 
    ", i, arr[i]);
        }
    
        //指针访问
        for(int *p = arr; p < arr + count; ++p)
        {
            printf("p the value is: %d 
    ", *p);
        }
    }
    
    
    int  main(int argc, char *argv[])
    {
        static int c[10]; //静态生存周期和语句块作用域
        //int d[10];      //具有自的生存周期和语句块作用域
    
        int vla[2*argc];  //自动生存周期,长度可变的数组
        //error: variable length array declaration can not have 'static' storage duration
        //static int e[n];  //精态生存周期,不能为长度可变数组
        //error: fields must have a constant size: 'variable length array in structure' extension will never be supported
        //struct S { int f[n] }; //小标签不能为长变可变数组名
        struct S { int f[10]; }; //小标签不能为长变可变数组名
        //多维数组
        extern int a2d[][5];
        //int a3d[2][2][3] = {{{110,111,112},{120,121,122}},{{210,211,212},{220,221,222}}};
        //int a3d[][2][3]  = {{{1},{4}},{{7,8}}};
        //int a3d[2][2][3] = {{1,0,0,4}, {7,8}};
        //int a3d[2][2][3] = {1, [0][1][0]=4, [1][0][0]=7,8};
        int a3d[2][2][3] = {{1}, [0][1]=4, [1][0]={7,8}};
    
    
        //初始化
        //int d[] = {1,2,3};
        //d[0] = 1, d[1]=2, d[2]=3;
        int d[10] = {1,2,3,[6]=6}; //初始化特定元素
        parray(10, d);
        
        return 1;
    }                                                                                                                                                                        
  • 相关阅读:
    C语言的AES加密
    curl指定域名的IP
    gdb调试知识
    C++获取寄存器eip的值
    C++嵌入lua
    [置顶] python字典和nametuple互相转换例子
    【python】redis基本命令和基本用法详解
    xshell登录到CentOS7上时出现“The remote SSH server rejected X11 forwarding request.
    selinue引起的ssh连接错误
    SCP和SFTP相同点和区别
  • 原文地址:https://www.cnblogs.com/abeen/p/4257351.html
Copyright © 2011-2022 走看看