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

  1. #include<stdio.h>
  2. #define ROWS 3
  3. #define COLS 4
  4. int sum2d(int rows, int cols, int ar[rows][cols]);
  5. int main(void)
  6. {
  7. int i, j;
  8. int rs = 3;
  9. int cs = 10;
  10. int junk[ROWS][COLS] =
  11. {
  12. 2, 4, 6, 8,
  13. 3, 5, 7, 9,
  14. 12, 10, 8, 6
  15. };
  16. int morejunk[ROWS - 1][COLS + 2] =
  17. {
  18. 20, 30, 40, 50, 60, 70,
  19. 5, 6, 7, 8, 9, 10
  20. };
  21. int vari[rs][cs]; // VLA
  22. for ( i = 0; i < rs; i++)
  23. for (j = 0; j < cs; j++)
  24. vari[i][j] = i * j + j;
  25. printf("3x5 array\n");
  26. printf("Sum of all elements = %d\n", sum2d(ROWS, COLS, junk));
  27. printf("2x6 array\n");
  28. printf("Sum of all elements = %d\n", sum2d(ROWS - 1, COLS + 2, morejunk));
  29. printf("3x10 VLA!\n");
  30. printf("Sum of all elements = %d\n", sum2d(rs, cs, vari));
  31. return 0;
  32. }
  33. int sum2d(int rows, int cols, int ar[rows][cols])
  34. {
  35. int r;
  36. int c;
  37. int tot;
  38. tot = 0;
  39. for (r = 0; r < rows ; r++)
  40. for (c = 0; c < cols; c ++)
  41. tot = tot + ar[r][c];
  42. return tot;
  43. }

  1. 3x5 array
  2. Sum of all elements = 80
  3. 2x6 array
  4. Sum of all elements = 315
  5. 3x10 VLA!
  6. 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. CentOS下永久修改主机名

    永久修改主机名 [root@centos7 ~]# vim /etc/hostname 打开之后将原来的名字改成你想换的名字 [root@centos7 ~]# cat /etc/hostname 查 ...

  2. hibernate查询方式(三)

    QBC查询 (Query By Criteria) *****QBC查询有三个特点 **查询时不写sql语句 而是用方法来查询 **操作实体类和属性 **通过criteria对象来实现 1.查询所有 ...

  3. jQuery中操作页面的文本和值

    主要是区分俩种方法: 1.html():可以识别HTML文件,将里面内容全部打印(操作双标签) 2.text():只是将里面的内容打印出来,不能识别HTML格式(操作双标签) <!DOCTYPE ...

  4. Python基础第二课

    字符串(引号):四种表达方式 n1 = "我是" n1 = '我是' n1 = """我是""" n1 = '" ...

  5. 在5分钟内将Spring Boot作为Windows服务启动

    分享优锐课学习笔记~来看一下如何使用Spring Boot创建Windows服务以及通过配置详细信息来快速启动并运行. 最近不得不将Spring Boot应用程序部署为Windows服务,感到惊讶的是 ...

  6. Python3 函数基础1

    目录 定义函数 定义函数的三种形式 空函数 有参函数 无参函数 函数的调用 函数的返回值 函数的参数 形参 (parameter) 实参(argument) 位置形参与位置实参 默认形参 关键字实参 ...

  7. 【JS】395-重温基础:事件

    本文是 重温基础 系列文章的第二十篇. 这是第三个基础系列的第一篇,欢迎持续关注呀!重温基础 系列的[初级]和[中级]的文章,已经统一整理到我的[Cute-JavaScript](http://js. ...

  8. 【Nodejs】326- 从零开发一个node命令行工具

    本文由 IMWeb 社区授权转载自腾讯内部 KM 论坛.点击阅读原文查看 IMWeb 社区更多精彩文章. 什么是命令行工具? 命令行工具(Cmmand Line Interface)简称cli,顾名思 ...

  9. Mysql添加path变量

    前提: 系统环境:Linux,服务器:阿里云轻量应用服务器 背景: 阿里云轻量应用服务器自带 mysql5.7,但是没有配置环境变量,因此直接输入 mysql -u root -p 将提示 comma ...

  10. c++之基础知识

    一.变量 作用:给一段指定的内存空间,方便操作这段内存. 语法:数据类型 变量名 = 初始值.int a = 10; 二.常量 作用:用于记录程序中不可更改的数据 c++定义常量有两种方式: #def ...