C lang: VLA(variable-length array)
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)的更多相关文章
- FireDAC 出现Variable length column[*] overflow. Value length - [80], column maximum length
FireDAC 出现Variable length column[*] overflow. Value length - [80], column maximum length FireDAC的 TF ...
- 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 ...
- 转:zero length array问题
单看这文章的标题,你可能会觉得好像没什么意思.你先别下这个结论,相信这篇文章会对你理解C语言有帮助.这篇文章产生的背景是在微博上,看到@Laruence同学出了一个关于C语言的题,微博链接.微博截图如 ...
- 0-3为变长序列建模modeling variable length sequences
在本节中,我们会讨论序列的长度是变化的,也是一个变量 we would like the length of sequence,n,to alse be a random variable 一个简单的 ...
- variable 'QJsonArray array' has initializer but incomplete type
variable "xxx" has initializer but incomplete type 编译报以上错误 分析:“xxx”对应的类型没有找到,没包含定义该变量类型的头文 ...
- C lang:Pointer and multidimensional array
Xx_Introduction Double indrection:Address of Address;Pointer of Pointer Ax_Code #include<stdio.h& ...
- 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 ...
- C语言关键字之sizeof
C语言关键字 sizeof 是一个操作符,返回对象或类型所占内存字节数,类型为size_t(定义在<stddef.h>),有2种用法: sizeof unary-expression si ...
- Do you master on array in C ?
Do you master on array in C ? 因为新标准C99的支持变长数组, 差点儿C的标准特性就是看着gcc来的(Linux 内核严重依赖GCC) int mani() { cons ...
随机推荐
- Python报错ERROR: Command errored out with exit status 1:
解决方法: 1.以管理员身份打开cmd 2.pip install robotframework-AutoItLibrary (本次安装时Python基于3.7.3,pip为最新版本) 3.安装成功
- Idea 2016 激活码
43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiI ...
- react文本溢出hover气泡显示全部文本——JS判断文本溢出
需求: 在文本溢出的时候,显示气泡 JS相关知识 // target js元素 const containerLength = target.width; //当前容器的宽度 const textLe ...
- JavaScript1 基础
JavaScript的组成 ·ECMAScript 描述了语言的语法和基本对象/ ·DOM 文档对象模型,描述处理网页内容/ BOM 浏览器对象模型 描述与浏览器进行交互的方法和接口 引入方式/ h ...
- java之面向对象
类的语法格式 public class Person{ //属性类的成员变量可以先声明,不用初始化,类成员变量具有初始值 String name; int age; //方法 public void ...
- 分布式监控告警平台Centreon快速使用
一. Centreon概述 Centreon是一款功能强大的分布式IT监控系统,它通过第三方组件可以实现对网络.操作系统和应用程序的监控:首先,它是开源的,我们可以免费使用它:其次,它的底层采用nag ...
- USB工业摄像头设计之上位机
在工业相机中对摄像头要求较高,且采集的图像数据要求是源数据,未经过任何处理. 为了兼容xp.win7(32bit 64bit) 程序采用VS2008 MFC编制,参考网上一些应用. CYUSB驱动与 ...
- Python多版本管理器pyenv
查看Linux版本 [root@web ~]# cat /etc/redhat-release CentOS Linux release (Core) [root@web ~]# uname -a L ...
- 深入解析http协议
当今web程序的开发技术真是百家争鸣,ASP.NET, PHP, JSP,Perl, AJAX 等等. 无论Web技术在未来如何发展,理解Web程序之间通信的基本协议相当重要, 因为它让我们理解了We ...
- php5.4.16执行shell脚本
因为要用到Python脚本,所以打算直接在PHP中直接调用系统命令system(). 要注意两点: 一.PHP5.3以上不存在安全模式,即要直接执行脚本不需要作任何其他配置. 二.system函数格式 ...