当前位置:网站首页>Create dynamic array
Create dynamic array
2022-06-25 05:13:00 【Ability with desire】
- explain
There are three important limitations to array type variables : The length of the array is fixed , You must know the array length at compile time , The array is only in the memory of the block statement that defines it .
Each program occupies a block of available memory space during execution , Used to store dynamically allocated objects , This memory space is called the free storage area or heap of the program .
C Language programs use a pair of standard library functions malloc and free Allocate storage space in free memory , and c++ Language uses new and delete Expressions implement the same function .
2. Definition of dynamic array
When dynamically allocating arrays , Just specify the type and array length , You don't have to name the array object ,new Expression returns a pointer to the first element of the newly allocated array :
int *pa = new int[10];// Initialize to 10 Elements
this new The expression is assigned an expression that contains 10 individual int An array of elements of type , And returns a pointer to the first element of the array , This return value initializes the pointer pia.
3. Initializing dynamically allocated arrays
If the array element has a class type , The class's default constructor will be used to implement initialization , If the array element is a built-in type , There is no initialization :
string *psa = new string[10] ;// Initialize to empty string
int *pia = new int[10]; // Not initialized
You can also use a pair of empty parentheses following the length of the array , Initialize the values of array elements . Parentheses require the compiler to initialize the array ,.
int *pia2 = new int[10]();
边栏推荐
- Edge loss 解读
- API interface management setup -eolinker4.0
- WPF uses Maui's self drawing logic
- Everything is an object
- How to install the blue lake plug-in to support Photoshop CC 2017
- CopyPlugin Invalid Options options should be array ValidationError: CopyPlugin Invalid Options
- 2021-03-23
- XSS (cross site script attack) summary (II)
- 两小时带你进入软件测试行业风口(附全套软件测试学习路线)
- SRC platform summary
猜你喜欢
随机推荐
Enhanced paste quill editor
Ranorex Studio 10.1 Crack
滲透測試-提權專題
Reading and writing of nodejs excel (.Xlsx) files
[keil] GPIO output macro definition of aducm4050 official library
OLAP analysis engine kylin4.0
How PHP gets the user's City
dotnet-exec 0.4.0 released
Array: force deduction dichotomy
Summary of SQL injection (I)
In depth understanding of line height and vertical align
2021-10-24
How to choose the years of investment in financial products?
Svg code snippet of loading animation
In Net 6 using dotnet format formatting code
Qdebug June 2022
Eyeshot 2022 Released
Teach you to write non maintainable PHP code step by step
Detailed summary of position positioning
Detailed summary of float









