[ASM C/C++] C语言数组
生活随笔
收集整理的这篇文章主要介绍了
[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 \n", i, arr[i]);}//指针访问for(int *p = arr; p < arr + count; ++p){printf("p the value is: %d \n", *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; }
与50位技术专家面对面20年技术见证,附赠技术全景图
总结
以上是生活随笔为你收集整理的[ASM C/C++] C语言数组的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: C语言及程序设计初步例程-33 三种循环
- 下一篇: C++语言基础 例程 设计模式简介