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. mac端口占用

    lsof -i tcp:port 可以查看该端口被什么程序占用,并显示PID port 替换成端口号, eg: lsof -i tcp:8081 kill pid 杀死PID

  2. 使用 webservice 实现 RPC 调用

    WebService 介绍 Web service 是一个平台独立的,低耦合的 web 的应用程序用于开发分布式的互操作的应用程序.Web Service 技术, 能使得运行在不同机器上的不同应用无须 ...

  3. [TimLinux] JavaScript 获取设置在CSS类中的属性值

    1. 设置属性值 // 常用方式 var myEl = document.getElementById('idMyEl'); myEl.style.display = "none" ...

  4. hdu4585Shaolin

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4585 题意: 第一个人ID为1,战斗力为1e9. 给定n,给出n个人的ID和战斗力. 每个人必须和战斗 ...

  5. Python抓取豆瓣电影top250!

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理.作者:404notfound  一直对爬虫感兴趣,学了python后正好看到 ...

  6. 【JS】382- JavaScript 模块化方案总结

    本文包含两部分,第一部分通过简明的描述介绍什么是 CommonJS.AMD.CMD.UMD.ES Module 以及它们的常见用法,第二部分则根据实际问题指出在正常的 webpack 构建过程中该如何 ...

  7. 解决oracle11g数据库监听连接不上问题

    java连接数据库报错12514,无法识别监听,但是PL客户端可以连接 oracle 监听 添加ip 同时修改tnsnames.ora.listener.ora将这两个文件中HOST后面的主机都修改为 ...

  8. 面试题-JS中的作用域相关问题

    对象类型: 原始数据类型存储的是值,而对象类型存储的是地址(指针).下面的这个例子就比较有意思了. 先看题: function test(person) { person.age = 26 perso ...

  9. JavaScript数组去重(12种方法,史上最全)

    参考博客:https://segmentfault.com/a/1190000016418021?utm_source=tag-newest

  10. 基于JavaScript google map集成流程

    google地图集成流程 一.获取Google Map API密钥 1.进入Google官网 => https://www.google.com.hk/ ,申请一个谷歌账号(如果没有)然后访问下 ...