C lang: Compound literal
Xx_Introduction
- C99 stantard.
- Upate array and struct a compound literal.
- Literal is date type value.In addition to symbolic constant a constant.
Ax_Code
#include<stdio.h>
#define COLS 4
int sum2d(const int ar[][COLS], int rows);
int sum (const int ar[], int n);
int main(void)
{
int total1, total2, total3;
int *pt1;
int (*pt2)[COLS];
pt1 = (int[]){10, 20};
pt2 = (int[][COLS]){{1, 2, 3, -9},{4, 5, 6, -8}};
total1 = sum(pt1, 2);
total2 = sum2d(pt2, 2);
total3 = sum((int []){4, 4, 4, 5, 5, 5}, 6); //compound literal
printf("total1 = %d\n", total1);
printf("total2 = %d\n", total2);
printf("total3 = %d\n", total3);
return 0;
}
int sum(const int ar [], int n)
{
int i;
int total = 0;
for (i = 0; i < n; i++)
total += ar[i];
return total;
}
int sum2d(const int ar[][COLS],int rows)
{
int r;
int c;
int tot = 0;
for (r = 0; r < rows; r++)
for (c = 0; c < COLS; c++)
tot = tot + ar[r][c];
return tot;
}
total1 = 30
total2 = 4
total3 = 27
C lang: Compound literal的更多相关文章
- C99新增内容之复合文字(compound literal)
前言: 最近在复习C,发现了一些新东西,例如:变长数组,复合文字,指针的兼容性等.今天先简单谈一下复合文字. 正文: 假如需要向带有一个int参量的函数传递一个值,您可以传递一个int变量,也可以传递 ...
- objective-c 语法快速过(3)
oc 里的匿名对象 oc 这里,很少用到,因为并不适用于oc的内存管理,只是面试笔试也许出现,要求能看懂,不要在项目里这样写,因为写匿名对象,会造成内存泄露 #import <Foundatio ...
- 【C】 03 - 数据类型
程序说到底就是对数据的处理,所以首先要弄清楚需要处理哪些数据,计算机如何存储这些数据.C语言根据需要,抽象出了一些基本数据类型和衍生数据类型.这些可以满足大部分需求,更复杂的抽象数据类型亦可通过它们来 ...
- jetty 最后版本类库树, 基本上大多数应用都够了
d:\jetty-distribution-8.1.17.v20150415\lib\annotations\javax.annotation-1.1.0.v201108011116.jarjavax ...
- C Primer Plus(第五版)10
第 10 章 数组和指针 在本章中你将学习下列内容: · 关键字: static (静态) · 运算符: & * (一元) · 创建与初始化数组的方法. · 指针(基于已学的基础知识)及指针和 ...
- 【IOS】IOS高速入门之OC语法
Objective-C 是 C 语言的超集 您还能够訪问标准 C 库例程,比如在stdlib.h和stdio.h中声明的那些例程. Objective-C 还是一种很动态的程序设计语言,并且这样的动态 ...
- 32Mybatis_mybatis逆向工程自动生成代码
实际工作中要用的.很重要! mybaits需要程序员自己编写sql语句,mybatis官方提供逆向工程 可以针对单表自动生成mybatis执行所需要的代码(mapper.java,mapper.xml ...
- C Primer Plus学习笔记(九)- 数组和指针
数组 数组由数据类型相同的同一系列元素组成 需要使用数组时,通过声明数组告诉编译器数组中内含多少元素和这些元素的类型 普通变量可以使用的类型,数组元素都可以用 float candy[365]; // ...
- C/C++ 操作符优先级
不能光转贴,有空要熟悉之后,要写点心得.现在发现 . 的优先级确实很高. C: Precedence Operator Description Associativity 1 ++ -- Suffix ...
随机推荐
- 华为OSPF与ACL综合应用
一. 实验拓扑图 二.实验要求 1.企业内网运行OSPF路由协议,区域规划如图所示:2.财务和研发所在的区域不受其他区域链路不稳定性影响:3.AR1.AR2.AR3只允许被IT登录管理:4.YF和CW ...
- HDU 5121 Just A Mistake
Just A Mistake Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others) ...
- POJ 3281 Dining(网络流-拆点)
Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will c ...
- 使用WebClient实现断点续传 重写
早上下个东西,半天不动,火冒三丈,我可是100M光纤... WebClient.Httpclient.HttpWebRequest.WebRequest 我选了了WebClient因为他封装的够好 断 ...
- Django 07
目录 ORM查询优化 only与defer(单表) select_related与prefetch_related(跨表) choices参数 MTV与MVC模型 Ajax简介 前后端传输数据编码格式 ...
- CodeForces - 556C Case of Matryoshkas (水题)
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at ...
- 比较typeof与instanceof
相同点: JavaScript中typeof和instanceof常用来判断一个变量是否为空,或者是什么类型的. 不同点: typeof的定义和用法: 返回值是一个字符串,用来说明变量的数据类型. 细 ...
- [译]C# 7系列,Part 5: private protected 访问修饰符
原文:https://blogs.msdn.microsoft.com/mazhou/2017/10/05/c-7-series-part-5-private-protected/ C#有几个可访问性 ...
- JS---另一个定时器:一次性的
之前学的定时器:setInterval和清除定时器 clearInterval(定时器id); //常用的,反复的执行 window.setInterval(function () { alert(& ...
- 利用Azure虚拟机安装Dynamics 365 Customer Engagement之十二:新增SQL Server可用性副本
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...