C语言中的数组的访问方式
闲下来,写的代码,很是简单,不解释,代码如下:
#include <stdio.h> int main(int argc, char **argv)
{
char cArray[] = "Hello,World!"; for(int i = ; i < ; i++){
printf("the cArray[%d]: %c", i, cArray[i]);
} for(int i = ; i < ; i++){
printf("%d[the cArray]: %c\n", i, i[cArray]);
} return ;
}
执行结果为:
the cArray[0]: H
the cArray[1]: e
the cArray[2]: l
the cArray[3]: l
the cArray[4]: o
the cArray[5]: ,
the cArray[6]: W
the cArray[7]: o
the cArray[8]: r
the cArray[9]: l
the cArray[10]: d
the cArray[11]: !
0[the cArray]: H
1[the cArray]: e
2[the cArray]: l
3[the cArray]: l
4[the cArray]: o
5[the cArray]: ,
6[the cArray]: W
7[the cArray]: o
8[the cArray]: r
9[the cArray]: l
10[the cArray]: d
11[the cArray]: !
将代码改为:
#include <stdio.h> int main(int argc, char **argv)
{
char cArray[] = "Hello,World!"; for(int i = ; i < ; i++){
printf("%c", cArray[i]);
}
printf("\n"); for(int i = ; i < ; i++){
printf("%c", i[cArray]);
}
printf("\n");
printf("%s\n", cArray); return ;
}
代码结果:
Hello,World!
Hello,World!
Hello,World!
关于数组的总结为:
1、可以使用数据名加下标访问,也可以使用下标加数组名访问
2、数组下标从0开始,不越界访问,需要程序员自己把握
3、字符数组可以直接赋值成字符串内容
C语言中的数组的访问方式的更多相关文章
- C语言中不同变量的访问方式
C语言中的变量大致可以分为全局变量,局部变量,堆变量和静态局部变量,这些不同的变量存储在不同的位置,有不同的生命周期.一般程序将内存分为数据段.代码段.栈段.堆段,这几类变量存储在不同的段中,造成了它 ...
- go语言中的数组切片:特立独行的可变数组
go语言中的数组切片:特立独行的可变数组 初看go语言中的slice,觉得是可变数组的一种很不错的实现,直接在语言语法的层面支持,操作方面比起java中的ArrayList方便了许多.但是在使用了一段 ...
- (C/C++学习)7.数组及其访问方式
说明:数组的数据类型是一种构造类型,而存储数组的内存是一段连续的存储区域.数组的数据类型决定了连续内存的访问方式,它包括数组的三要素:起始地址.步长以及元素个数. 一.一维数组 1.形式:type 数 ...
- Go 语言中的数组是一种 值类型(不像 C/C++ 中是指向首元素的指针)
the-way-to-go_ZH_CN/07.1.md at master · Unknwon/the-way-to-go_ZH_CN https://github.com/Unknwon/the-w ...
- Go语言中的数组与数组切片
Go中的数组与C的数组一样,只是定义方法不同 c: int a[10][10] Go [10][10]int 定义并初始化 array1 := [5]int{1,2,3,4,5} 变量名 := [in ...
- C语言中结构体内存存储方式
C语言中结构体内存存储方式 结构体的默认存储方式采用以最大字节元素字节数对其方式进行对齐,例如一个结构体中定义有char.int类型元素,则结构体存储空间按照int类型占用字节,如果还有double类 ...
- Go语言中底层数组和切片的关系以及数组扩容规则
Go语言中底层数组和切片的关系以及数组扩容规则 demo package main import ( "fmt" ) func main() { // 声明一个底层数组,长度为10 ...
- c语言中字符串数组初始化的一点总结&& c++访问控制的三种方式
char *c[]={"ONE","TWO","THREE","FOUR"}; // c语言中定义了一个字符串数组(也称 ...
- C语言中的数组和指针以及字符串
数组名同时也是该数组首元素的地址,而指针提供了一种用来使用地址的符号方法,因此指针能够很有效地处理数组. 将一个整数加给指针,这个整数会和指针所指类型的字节数相乘,然后所得的结果会加到初始地址上 da ...
随机推荐
- NOIP模拟赛 数列
Problem 2 数列(seq.cpp/c/pas) [题目描述] a[1]=a[2]=a[3]=1 a[x]=a[x-3]+a[x-1] (x>3) 求a数列的第n项对1000000007 ...
- java工作环境配置jdk,idea
下载 jdk 1.8 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 配置环境 ...
- k8s资源指标API及metrics-server资源监控
简述: 在k8s早期版本中,对资源的监控使用的是heapster的资源监控工具. 但是从 Kubernetes 1.8 开始,Kubernetes 通过 Metrics API 获取资源使用指标,例如 ...
- Inkscape基础
What is Inkscape A program for creating vector graphics For Windows, Mac OS, and Linux Open source F ...
- angular4使用代理
1. 在angular-cli项目根目录下创建proxy.config.json { "/api/v1": { "target": "http://1 ...
- linux 安装elasticsearch
一.检测是否已经安装的elasticsearch ps aux|grep elasticsearch. 二.下载elasticsearch.tar.gz并上传至服务器usr/local/文件夹下 三. ...
- POJ:2109-Power of Cryptography(关于double的误差)
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Description Current work in cryptograp ...
- Leetcode 559. N叉树的最大深度
题目链接 https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree/description/ 题目描述 给定一个N叉树,找到其最大深度. ...
- urlopen SSL证书验证
错误描述: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777) 解决方法 ...
- Ubuntu下安装anaconda和pycharm
折腾了一上午,终于装好了,如下:Python环境的安装: 安装anaconda 建议去https://www.anaconda.com/download/#linux直接用Ubuntu界面的搜狐浏览器 ...