Xx_VLA Introduction

  • VLA:variable-length array,not variable array size,but variable arary dimensionality size.
  • Must be an automatic storage type
  • They cannot be initialized in a declaration
  • VLA is new feature,depend on compiler support.

Ax_Code

#include<stdio.h>
#define ROWS 3
#define COLS 4
int sum2d(int rows, int cols, int ar[rows][cols]); int main(void)
{
int i, j;
int rs = 3;
int cs = 10;
int junk[ROWS][COLS] =
{
2, 4, 6, 8,
3, 5, 7, 9,
12, 10, 8, 6
}; int morejunk[ROWS - 1][COLS + 2] =
{
20, 30, 40, 50, 60, 70,
5, 6, 7, 8, 9, 10
}; int vari[rs][cs]; // VLA for ( i = 0; i < rs; i++)
for (j = 0; j < cs; j++)
vari[i][j] = i * j + j;
printf("3x5 array\n");
printf("Sum of all elements = %d\n", sum2d(ROWS, COLS, junk));
printf("2x6 array\n");
printf("Sum of all elements = %d\n", sum2d(ROWS - 1, COLS + 2, morejunk));
printf("3x10 VLA!\n");
printf("Sum of all elements = %d\n", sum2d(rs, cs, vari)); return 0;
} int sum2d(int rows, int cols, int ar[rows][cols])
{
int r;
int c;
int tot;
tot = 0; for (r = 0; r < rows ; r++)
for (c = 0; c < cols; c ++)
tot = tot + ar[r][c]; return tot;
}

3x5 array
Sum of all elements = 80
2x6 array
Sum of all elements = 315
3x10 VLA!
Sum of all elements = 270

END

C lang: VLA(variable-length array)的更多相关文章

  1. FireDAC 出现Variable length column[*] overflow. Value length - [80], column maximum length

    FireDAC 出现Variable length column[*] overflow. Value length - [80], column maximum length FireDAC的 TF ...

  2. spark模型error java.lang.IllegalArgumentException: Row length is 0

    failure: Lost task 18.3 in stage 17.0 (TID 59784,XXXXX, executor 19): java.lang.IllegalArgumentExcep ...

  3. 转:zero length array问题

    单看这文章的标题,你可能会觉得好像没什么意思.你先别下这个结论,相信这篇文章会对你理解C语言有帮助.这篇文章产生的背景是在微博上,看到@Laruence同学出了一个关于C语言的题,微博链接.微博截图如 ...

  4. 0-3为变长序列建模modeling variable length sequences

    在本节中,我们会讨论序列的长度是变化的,也是一个变量 we would like the length of sequence,n,to alse be a random variable 一个简单的 ...

  5. variable 'QJsonArray array' has initializer but incomplete type

    variable "xxx" has initializer but incomplete type 编译报以上错误 分析:“xxx”对应的类型没有找到,没包含定义该变量类型的头文 ...

  6. C lang:Pointer and multidimensional array

    Xx_Introduction Double indrection:Address of Address;Pointer of Pointer Ax_Code #include<stdio.h& ...

  7. expand gcc case variable length

    daniel@daniel-mint ~/vex $ bash gen.sh 0x10 0x1F case 10: case 11: case 12: case 13: case 14: case 1 ...

  8. C语言关键字之sizeof

    C语言关键字 sizeof 是一个操作符,返回对象或类型所占内存字节数,类型为size_t(定义在<stddef.h>),有2种用法: sizeof unary-expression si ...

  9. Do you master on array in C ?

    Do you master on array in C ? 因为新标准C99的支持变长数组, 差点儿C的标准特性就是看着gcc来的(Linux 内核严重依赖GCC) int mani() { cons ...

随机推荐

  1. Maven学习整理

    1. window系统中安装Maven 2. 解决使用代理联网时无法下载jar包 3. 配置本地仓库 4. 处理本地仓库和中央仓库都没有依赖的jar包的情况

  2. luogu P1807 最长路_NOI导刊2010提高(07)

    题目描述 设G为有n个顶点的有向无环图,G中各顶点的编号为1到n,且当为G中的一条边时有i < j.设w(i,j)为边的长度,请设计算法,计算图G中<1,n>间的最长路径. 输入格式 ...

  3. kafka - java.nio.file.FileSystemException

    在启动Kafka时报错无法启动 E:\kafka_2.12-2.3.1\kafka-logs\__consumer_offsets-48\00000000000000000000.timeindex. ...

  4. CoderForces Round526 (A~E)题解

    A. The Fair Nut and Elevator time limit per test 1 second memory limit per test 256 megabytes input ...

  5. HDU2482-Transit search(地图还原+SPFA)

    Henry decides to develop a web site, which will provide the service of transit search. But he can on ...

  6. B. Magic Stick

    题目:魔法棒 题意:可以对一个正数进行变换,如果数字是偶数,那么它可以变成3 * a / 2 如果这个数大于1,那么它可以变成a - 1 有两个数x和y,询问是否可以通过这些操作从x变成y,输出YES ...

  7. ARTS-S pytorch中backward函数的gradient参数作用

    导数偏导数的数学定义 参考资料1和2中对导数偏导数的定义都非常明确.导数和偏导数都是函数对自变量而言.从数学定义上讲,求导或者求偏导只有函数对自变量,其余任何情况都是错的.但是很多机器学习的资料和开源 ...

  8. DWVA-关于SQL注入的漏洞详解

    low等级 代码如下: <?php if( isset( $_REQUEST[ 'Submit' ] ) ) { // Get input $id = $_REQUEST[ 'id' ]; // ...

  9. Electron node integration enabled 设置

    解决办法 参考博客:https://blog.csdn.net/hwytree/article/details/103167175

  10. 从零开始—Socket系统调用和多态封装

    1 重新搭建实验环境 前面都是用实验楼环境做的实验,偷的懒总是要还的,这一次重装环境前后花了十几个小时,踩了无数的坑. 1.1 Ubuntu和LINUX内核的区别 Ubuntu是基于LINUX内核编写 ...