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 ...
随机推荐
- FF.PyAdmin 接口服务/后台管理微框架 (Flask+LayUI)
源码(有兴趣的朋友请Star一下) github: https://github.com/fufuok/FF.PyAdmin gitee: https://gitee.com/fufuok/FF.Py ...
- 【原创】004 | 搭上SpringBoot事务诡异事件分析专车
前言 如果这是你第二次看到师长,说明你在觊觎我的美色! 点赞+关注再看,养成习惯 没别的意思,就是需要你的窥屏^_^ 本专车系列文章 目前连载到第四篇,本专题是深入讲解Springboot源码,毕竟是 ...
- elasticsearch中mapping全解实战
目录 Mapping简介 Mapping Type 分词器最佳实践 字段类型 text 类型 keyword 类型 date类型 object类型 nest类型 range类型 实战:同时使用keyw ...
- 正则replace 回调函数里接收的参数是什么?
前言 我们都知道 replace 在做替换处理方面会很常用,通常也是第一个会想到的方法.replace 第一个参数可以传入 string 或 RegExp,第二个参数可以传入 string 或 一个回 ...
- 开通博客第一天,记录此时此刻,开始学习加强c#
从2017年6月毕业到现在,不断的学习.net,在工作中不断的加强技术,终于在此时此刻决定开通博客,记录此后每一天学习的技术点,两年来,每天所涉及的技术点很杂,学了这个忘了那个,总感觉在进步却总是觉得 ...
- deconstructSigs|探寻cosmic的独特“气质”-mutation signature !
deconstructSigs-mutation signature看一下你的数据是什么“气质”的? 本文首发于“生信补给站” https://mp.weixin.qq.com/s/k7yzk9hPX ...
- JSP注册登录页教程
转载请标明原文地址:http://www.cnblogs.com/zhangyukof/p/6785258.html 一.准备工作 已搭建好的SSH框架工程一个,如果没有,请参考我的上一篇文章< ...
- JS---BOM---定时器
定时器 参数1:函数 参数2:时间---毫秒---1000毫秒--1秒 执行过程: 页面加载完毕后, 过了1秒, 执行一次函数的代码, 又过了1秒再执行函数..... 返回值就是定时器的id值 v ...
- Cesium专栏-雷达遮罩动态扫描(附源码下载)
Cesium 是一款面向三维地球和地图的,世界级的JavaScript开源产品.它提供了基于JavaScript语言的开发包,方便用户快速搭建一款零插件的虚拟地球Web应用,并在性能,精度,渲染质量以 ...
- 可以设置实体在Dynamics 365高级查找中不显示吗?
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...