当前位置:网站首页>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.
边栏推荐
- Why is continuous integration and deployment important in development?
- nacos注册中心
- SQL server当存储过程接收的参数是int类型时,如何做判断?
- LDP --- 标签分发协议
- Code ~ hide or disable the status bar and virtual keys
- Why does the 20 bit address bus determine the storage space of 1MB
- Lucifer 98 life record ing
- mmdetection初步使用
- Configmap configuration and secret encryption
- Solve the delay in opening the console of Google browser
猜你喜欢

SQL window function

LVS+KeepAlived高可用部署实战应用

1. Mx6u driver development-2-led driver

Three tier architecture of enterprise network

UCOS任务切换过程

初识C语言(3)

Shutter start white screen

Ssl== certificate related concepts

Ma Zhixing entered the mass production of front loading, starting with the self-developed domain controller?

Getting started with caspin
随机推荐
lodash库常用方法
【redis系列】字符串数据结构
大厂们终于无法忍受“加一秒”了,微软谷歌Meta等公司提议废除闰秒
企业网的三层架构
3.解决Pycharm报错Unresolved reference ‘selenium‘ Unresolved reference ‘webdriver‘
The const keyword of ES6 declares variables
Why does the 20 bit address bus determine the storage space of 1MB
内连接和左连接简单案例
Ribbon principle analysis namedcontextfactory
Common methods of lodash Library
Deep understanding of Base64 underlying principles
RHCE's at, crontab's basic operations, the Chrony service, symmetric encryption and asymmetric encryption
LVS+KeepAlived高可用部署实战应用
Remote desktop connection error
SFTP upload error: com.jcraft.jsch JSchException: connection is closed by foreign host
Android view system and custom view Series 1: (kotlin version)
Some notes on uniapp
How fast does it take to implement a super simple language
Data too long for column 'xxx' at row 1 solution
Flutter 启动白屏