当前位置:网站首页>When defining an array, the size must be constant
When defining an array, the size must be constant
2022-07-29 04:00:00 【Xiaowa 123】
Sometimes we need to dynamically determine the size of the array , The following methods may be adopted :
int n=5;
int a[n];
Be careful : The above definition is wrong , Because when defining an array , The size of the array must be explicitly determined , Such as int a[5], The size of the array must be a constant , In this way, the compiler can allocate a certain and accurate space to the data .
It can be understood in this way :
1. When defining an array, the allocation of memory is already involved , If the compiler finds that the size of the array is not given directly when allocating space to the array , It's a variable , If this variable is not initialized , The system randomly assigns a value , The size of the array is also uncertain .
2. If you want to dynamically allocate the array size according to your needs , Use pointer +malloc Methods , Dynamically allocate an array in the heap , Use a pointer to access this array , Is a more flexible way .
summary : When defining an array , Be sure to specify the specific size of the array , Otherwise, some compilers will report errors , such as vs.
边栏推荐
- How to understand "page storage management scheme"
- Why is continuous integration and deployment important in development?
- JS cookie usage
- HCIP BGP
- 力扣面试题17.04 消失的数字||260.只出现一次的数字(内含位运算知识点)
- Use case of arrow function of new features in ES6
- 关于双指针的思想总结
- CUB_ Visualization of key points in 200 bird dataset
- 大厂们终于无法忍受“加一秒”了,微软谷歌Meta等公司提议废除闰秒
- Typescript from getting started to mastering (XXII) namespace namespace (I)
猜你喜欢
随机推荐
First knowledge of C language (3)
Typescript from introduction to proficiency (XXIV) using import syntax
Analysis of new retail o2o e-commerce model
Shutter start white screen
nacos注册中心
Casbin入门
1985-2020 (8 Editions) global surface coverage download and introduction
LDP -- label distribution protocol
SSL==证书相关概念
Wechat applet monitors sliding events on the screen
Opensql quick learning
CUB_ Visualization of key points in 200 bird dataset
Raft protocol - process demonstration
消费行业数字化升级成 “刚需”,weiit 新零售 SaaS 为企业赋能!
Data mining -- Introduction to the basis of association analysis (Part 1)
Typescript from getting started to mastering (XXIII) namespace namespace (Part 2)
Summary on the thought of double pointer
力扣面试题17.04 消失的数字||260.只出现一次的数字(内含位运算知识点)
Data too long for column 'xxx' at row 1 solution
Deep understanding of browser caching mechanism (HTTP)









