C语言程序设计数组和算法基础
今天我们学习C语言程序设计第6章——数组和算法基础的内容。今天的主要内容有三部分,分别是一维数组的定义和初始化,二维数组的定义和初始化,向函数传递一维数组。
Today we are studying C Programming Chapter 6 - Arrays and Algorithmic Foundations. There are three main parts to today"s topic: defining and initialising one-dimensional arrays, defining and initialising two-dimensional arrays, and passing one-dimensional arrays to functions.
No. 1 一维数组的定义和初始化
数组是一组具有相同类型的变量的集合,它是一种顺序存储,随机访问的顺序表结构。数组名就是用来标识这组相同类型的数据。构成数组的每个元素项称为数组元素。C程序通过数组的下标实现对数组元素的访问。
一维数组的一般定义格式为:
类型 数组名【元素个数】;
An array is a collection of variables of the same type; it is a sequential table structure stored in order and accessed randomly. The name of the array is used to identify the set of data of the same type. Each element of an array is called an array element, and C programs access the elements of an array by means of its subscripts.
The general definition of a one-dimensional array is in the following format
type array name [number of elements].
No. 2二维数组的定义和初始化
二维数组的一般定义格式为:
类型 数组名【第一维长度】【第二维长度】;
第一维的长度代表数组每一列的元素个数,第二维的长度代表数组每一行的元素个数。例如:short matrix[3][4];
一维数组在内存中占用的字节数为:数组长度*sizeof(基类型),二维数组占用的字节数为:第一维长度*第二维长度*sizeof(基类型)
The general format of the definition of a two-dimensional array is
type array name [length of the first dimension] [length of the second dimension].
The length of the first dimension represents the number of elements in each column of the array, and the length of the second dimension represents the number of elements in each row of the array. Example: short matrix[3][4].
The number of bytes occupied by a one-dimensional array in memory is: array length * sizeof (base type), the number of bytes occupied by a two-dimensional array is: length of the first dimension * length of the second dimension * sizeof (base type)
No. 3向函数传递一维数组
数组元素和基本型变量一样,既可出现在任何合法的C表达式中,也可用作函数参数。
若要把一个数组传递给一个函数,那么只要使用不带括号的数组名作为函数实参调用函数即可。
由于数组名代表数组第一个元素的地址,因此用数组名作函数实参实际上是将数组的首地址传给被调函数。
Array elements, like basic variables, can appear in any legal C expression and can also be used as function parameters.
To pass an array to a function, simply call the function using the array name without parentheses as a function reference.
As the array name represents the address of the first element of the array, using the array name as a function reference is in effect passing the first address of the array to the function being called.
注意:1.C语言中数组的下标都是从0开始的。
2.在不同编译系统中,int型所占的字节数是不同的。使用sizeof运算符来计算一个类型或变量在内存中所占的字节数更利于提高程序的可移植性。
3.数组第二维的长度声明永远都不能省略。
4.数组做函数形参时,数组的长度可以不出现在数组名后面的方括号内,通常用另一个整型形参来指定数组的长度。
Note: 1. The subscripts of arrays in C all start from 0.
2. The number of bytes occupied by an int type varies from one compilation system to another. It is better to use the sizeof operator to calculate the number of bytes in memory for a type or variable to improve program portability.
3. The length declaration of the second dimension of an array should never be omitted.
4. When an array is used as a formal reference to a function, the length of the array may not appear in the square brackets after the array name, but is usually specified by another integer formal reference.
参考资料:文字:百度;图片:微博;翻译:百度翻译
本文由LearningYard新学苑原创,部分图片文字来自网络,如有侵权请联系。
舒畅凌晨晒手绘图为刘亦菲庆生,称其为我滴仙女,羡慕8月25日是刘亦菲34岁生日,舒畅晒手绘图为其庆生,发文我滴仙女,生日快乐,我就是那只兔子。几乎每年舒畅都发文庆祝刘亦菲生日,两人从2003年拍摄金粉世家相识,结下深厚友谊,网友表
朱珠顺利生娃,宝宝也有梨涡,完美继承父母的高颜值9月2日,朱珠在社交平台上分享宝宝照片,官宣当妈妈了,从照片上看小宝宝的颜值完美继承了爸妈的优点,不少网友评论这小宝宝太会长了,居然有妈妈的梨涡,而且小脸嘟嘟的,还面带微笑,真的太
杨迪的热搜怎么会如此搞笑呢,这次又是杨迪耍小牌,扣扣搜搜近日,有网友爆料杨迪只喝康师傅,如果节目现场没有这个牌子,他宁可只喝白水也不会喝其他牌子。对此网友翻译了下只能喝超市最便宜的矿泉水。对此,杨迪发文回应此事为什么我连爆料都和别人不一
近几年的华语乐坛是否进入了新声代女歌手百花齐放的时代?近几年来,新声代女歌手如雨后春笋般涌现。她们用一首首好的作品树立口碑,渐渐占据着各大音乐平台。唱歌天赋顶级的邓紫棋,创作能力强,作品流传度相当广,是少有的扛起90后大梁的国民度和实
歌手被批综艺混子,不参加综艺谁养他们啊?众所周知,我国娱乐圈演员的收入那是相当高的,郑爽阴阳合同一签,拍摄一部电影片酬就有1。6亿,仔细一算,日薪208万,不少人年薪还不到他日薪的零头。近两日在热搜高挂的苏芒更是在节目中
支付方劳务报酬的六大税收雷区下面几个都是最常见的关于劳务报酬开发票的事情。注意保存哦!01hr支付给个人的费用,认为个人开不了发票,就不开发票了。这个认知绝对是错误的,个人是可以去税务局代开发票的。根据中华人
一文看懂进项税额不予抵扣的8种情况进项税额不是全能抵扣的,今天汇总了常见的8种情况,还附有案例详解,一起来看一下吧。一用于简易计税方法计税项目免征增值税项目集体福利或者个人消费的购进货物加工修理修配劳务服务无形资产
微信付费时代真的要来了吗?商标已经申请注册众所周知,微信是国内最大的社交应用软件,截至今年6月底,微信全球的月活跃用户达到12。5亿。在国内只要是智能手机用户,基本都是微信的用户。作为腾讯旗下的两大社交应用,微信与QQ的主
骂她强捧之耻,一点都不冤,观众缘不是玄学观众缘不是玄学。扫黑风暴爆了,幸运的是,江疏影又有参演,悲催的是,她被观众认为是多余的那个。这部剧里女演员不多,除了饰演贺云的吴越,江疏影几乎是唯一一个叫得上名字的当红女明星。不管
对痛苦的思考才是财富我们经常都能听到的一句话是,先苦后甜,不要在该吃苦的年纪选择安逸大部分人的想法是只要我们努力了,以后就会得到回报。然而埋头苦干所吃下的苦,从来都不是人生财富。正相反吃苦不是能力,而
市场拆迁后市场要被拆了的传闻已久,但迟迟未见动作。反倒让原本慌乱的商户们沉下心来,该做生意做生意,只是耳朵竖的更高了,毕竟市场拆迁是关乎生存的大事。该来的还是来了。市场拆迁的命令下的突然,要