Examples of one-dimensional dynamic arrays :

 #include <iostream>
using namespace std;
int main()
{
int *arr;
int n;
cout<<" Please enter an integer to specify the size of the array :";
cin>>n;
arr = new int[n];
for(int i=;i<=n;i++)
{
cout<<" Please enter the first "<<i<<" Elements :";
cin>>arr[i-];
}
cout<<endl;// Output a blank line
for(int i=;i<=n;i++)
{
cout<<" The first "<<i<<" The element is :"<<arr[i-]<<endl;
}
delete [] arr;// Dynamic space release
}

Examples of two-dimensional dynamic arrays :

 #include <iostream>
using namespace std;
int main()
{
int **arr;
int n=,m=;
cout<<" Please enter an integer to specify the first dimension of the array :";
cin >> n;
cout<<" Enter an integer to specify the second dimension of the array :";
cin>>m;
arr = new int*[n];
for(int i=;i<n;i++) // Create dynamic array
{
arr[i] = new int[m];
}
cout<<"***************** Here's the input section *****************"<<endl;
for(int i=;i<n;i++)// Read in array elements
{
for(int j =;j<m;j++)
{
cout<<" Please enter "<<"arr["<<i<<"]["<<j<<"] Value :";
cin>>arr[i][j];
}
} cout<<"***************** Here's the output section *****************"<<endl;
for(int i=;i<n;i++)// Output array elements
{
for(int j =;j<m;j++)
{
cout<<"arr["<<i<<"]["<<j<<"]="<<arr[i][j]<<endl;
}
}
for(int i=;i<n;i++)// Dynamic space release
delete[] arr[i];
delete[] arr;
arr=NULL;
}

C++ Dynamic array instance of more related articles

  1. C++ About China [] Static arrays and new The difference analysis of the dynamic array of allocation

    This article mainly introduces C++ About China [] Static arrays and new The difference analysis of the dynamic array of allocation , Very important concept , Friends in need can refer to This paper analyzes with examples C++ About language [] Static arrays and new The difference between allocated dynamic arrays , Can help you add ...

  2. The order storage structure of linear table (C Language dynamic array implementation )

    Definition of linear table :N A finite sequence of data elements From the storage structure, linear table is divided into : Sequential storage structure ( Array ) and Chain storage structure ( Linked list ) Sequential storage structure : It uses a continuous memory space to store the data in the table  L=(a1,a2,a3....an) chain ...

  3. ArrayList Class source code analysis ——ArrayList Dynamic array implementation details ( be based on JDK8)

    One . Basic concepts ArrayList Is an object element that can be added , And to modify the elements, query, delete and other operations of the container class .ArrayList The bottom layer is implemented by arrays , So just like arrays, you can query the elements contained in the container object quickly and randomly according to the index ...

  4. Activiti User task parallel dynamic multi instance ( Multi user execution process )

    In many cases , We need multiple users to execute the rest of the process , Like the meeting process : The leader initiated a meeting , Choose the person in the meeting ( Multiple ) Every meeting member needs to sign in after receiving the notice ( The check-in of one user will not affect the check-in of another user ) After the check-in is completed, the process ends If ...

  5. [UE4] The dynamic array :TArray Containers

    Why use UE4 The container class provided ? If you used C++ Of STL library , You will know STL A variety of containers are available / data structure , It makes you very efficient when dealing with a lot of data .UE4 A similar library is also provided , The types in the library are based on T At the beginning , ...

  6. array of TVarRec Dynamic arrays use

    FDQuery.AppendRecord() There is a array of TVarRec. We usually use it directly [Var1,Var2,...]. This is manual input , But if we don't know the added elements in advance , We have to declare a arr ...

  7. JAVA data structure --ArrayList The dynamic array

    In computer science , The dynamic array , Extensible arrays , Adjustable array , Dynamic table , Variable array or array list is a random access variable size list data structure , Allow elements to be added or removed . It provides a standard library of many modern mainstream programming languages . Dynamic array overcomes the limitation of static array , static ...

  8. C# Collection classes : The dynamic array 、 queue 、 Stack 、 Hashtable 、 Dictionaries ( turn )

    1. The dynamic array :ArrayList The main method :Add.AddRange.RemoveAt.Remove 2. queue :Queue The main method :Enqueue Queue entry .Dequeue Outgoing queue .Peek return Queue ...

  9. C# Collection classes : The dynamic array 、 queue 、 Stack 、 Hashtable 、 Dictionaries

    1. The dynamic array :ArrayList The main method :Add.AddRange.RemoveAt.Remove 2. queue :Queue The main method :Enqueue Queue entry .Dequeue Outgoing queue .Peek return Queue ...

Random recommendation

  1. Regular Expression Matching a Labeled href

    JS Code : <html> <head> <script language="javascript"> var a='<P><A ...

  2. Linux Next tcp agreement socket Of recv Function return time analysis ( Sticky package )

    http://www.vckbase.com/index.php/wv/10http://blog.csdn.net/zlzlei/article/details/7689409 Article 1 : Currently on the Internet ...

  3. Coursera Machine learning course (2016 ) Set of wrong questions

    Unit 4 Neural Networks (×) analysis : It is estimated that D Item error , Because when neural networks deal with logic operations, they are range(0,1), But when dealing with other operations, it's not in this range (√) ( Yes ) week 6 ...

  4. Cross process communication Messenger

    1. brief introduction Messenger, As the name suggests, it is a messenger , Through it, you can pass... In different processes Message object , By means of Message Put in the entry we need , You can easily transfer data across processes .Messenger It's a lightweight ...

  5. 20145232 Han Wenhao 《 Network countermeasure technology 》 Web Basics

    Apache Because the port number 80 Already occupied ( It was set up in the last experiment ), So first modify /etc/apache2/ports.conf The port in is 5232 Then turn it back on Can be entered in the browser localhost:5208 To see if ...

  6. Self study Huawei IoT The Internet of things _11 Introduction to the Internet of things operating system

    Click back to self study Huawei IoT Logistics network Self study Huawei IoT The Internet of things _11  Introduction to the Internet of things operating system 1.1  The difficulties facing the Internet of things Difficulties in the development of Internet of things terminals : Developers need to understand the difference between hardware and chips , Self adapting hardware interface Difficulties in the development of the Internet of things ...

  7. Spring Series of Spring Summary of common notes Reprint

    Spring Series of Spring Summary of common notes   Conventional Spring The way is to use .xml The document is right bean Injection or configuration aop. thing , There are two disadvantages to this :1. If all content is configured in .xml In file , that .x ...

  8. Python Files and exceptions

    Programs and runtime data reside in memory , Where it comes to data exchange , Usually disk . Network, etc , Therefore need IO Interface . IO Programming ,Stream( flow ) It's a very important concept , Think of the flow as a pipe , The data is the water in the pipe , But only one ...

  9. VS2010 plug-in unit VS.PHP Debugging and development php Program

    VS plug-in unit VS.PHP debugging PHP Methods ; Have to say vs Powerful , This breakpoint debugging function is in zend Can't do it Pictured : After setting successfully , It's like debugging .Net The procedure is the same Php Procedure ! Debugging steps : 1. Where debugging is needed ...

  10. NOSQL Quick start

    NoSql It's a very old concept , But for myself , It's still a short board , Make up for . Let's start with a few simple examples NOSQL The situation at home (2013 Data for about two years , It's a bit out of date ), For example, Sina Weibo , There are many 200 Multiple physical machines are running ...