当前位置:网站首页>C语言-数组的定义方式
C语言-数组的定义方式
2022-06-12 05:30:00 【Wildcraner】
一、一维数组
静态 int array[100]; 定义了数组array,并未对数组进行初始化
静态 int array[100] = {1,2}; 定义并初始化了数组array
动态 int* array = new int[100]; delete []array; 分配了长度为100的数组array
动态 int* array = new int100; delete []array; 为长度为100的数组array初始化前两个元素
二、二维数组
静态 int array[10][10]; 定义了数组,并未初始化
静态 int array[10][10] = { {1,1} , {2,2} }; 数组初始化了array[0][0,1]及array[1][0,1]
动态 int (array)[n] = new int[m][n]; delete []array;
动态 int* array = new int*[m]; for(i) array[i] = new int[n]; for(i) delete []array[i]; delete []array; 多次析构
动态 int* array = new int[m][n]; delete []array; 数组按行存储
三、***数组
int* array = new int[m][3][4]; 只有第一维可以是变量,其他维数必须是常量,否则会报错
delete []array; 必须进行内存释放,否则内存将泄漏
四、数组作为函数形参传递
一维数组传递:
void func(int* array);
void func(int array[]);
二维数组传递:
void func(int** array);
void func(int (*array)[n]);
数组名作为函数形参时,在函数体内,其失去了本身的内涵,仅仅只是一个指针,而且在其失去其内涵的同时,它还失去了其常量特性,可以作自增、自减等操作,可以被修改。
五、字符数组
char类型的数组被常委字符数组,在字符数组中最后一位为转移字符’\0’(也被成为空字符),该字符表示字符串已结束。在C++中定义了string类,在Visual C++中定义了Cstring类。
字符串中每一个字符占用一个字节,再加上最后一个空字符。如:
char array[10] = “cnblogs”;
虽然只有7个字节,但是字符串长度为8个字节。
也可以不用定义字符串长度,如:
char array[] = “cnblogs”;
边栏推荐
- 关于架构(排名不分先后)
- 20000 word detailed reptile knowledge reserve, basic exercises of data collection and cleaning (I) reference answers to the first song
- Some optimization methods for UI Application of Qt5 on Hisilicon security platform
- CentOS compiling and installing mysql8.0
- Rv1109 lvgl UI development
- Matlab: halftone and dither conversion
- Thingsboard create RCP widget
- Nbiot module me3616 at command mqtt connecting thingsboard
- Save the object in redis, save the bean in redis hash, and attach the bean map interoperation tool class
- Detailed explanation of data envelopment analysis (DEA) (taking the 8th Ningxia provincial competition as an example)
猜你喜欢

国企为什么要上市

4.3 模拟浏览器操作和页面等待(显示等待和隐式等待、句柄)

Detailed analysis of mathematical modeling problem a (vaccine production scheduling problem) of May Day cup in 2021

How Wireshark decrypts WiFi data packets

Detailed usage of vim editor

38. 外观数列

Servlet core

Multi thread learning 4. Sleep, wait, yield, join (), ThreadGroup control the running of threads

公司注册认缴资金多久

16. Somme des trois plus proches
随机推荐
Quickly get PCA (principal component analysis) (principle code case)
Necessary for Test Engineer -- package capturing tool fiddler
AddUser add user and mount hard disk
Some optimization methods for UI Application of Qt5 on Hisilicon security platform
16. sum of the nearest three numbers
12.26 exercise summary
Stm32f4 ll library multi-channel ADC
beginning一款非常优秀的emlog主题v3.1,支持Emlog Pro
论文阅读_图神经网络GIN
JS how to get the date
Detailed analysis of the 2021 central China Cup Title A (color selection of mosaic tiles)
62. the last number left in the circle
New knowledge today
14- II. Cutting rope II
WebRTC AEC 流程解析
Set common methods
Towards End-to-End Lane Detection: an Instance SegmentationApproach
67. convert string to integer
The combined application of TOPSIS and fuzzy borde (taking the second Dawan District cup and the national championship as examples, it may cause misunderstanding, and the Dawan District cup will be up
Multi thread learning v. volatile visibility and cache inconsistency, instruction reordering