c#读取整数空格
Prerequisite: new and delete operator in C++
先决条件: C ++中的new和delete运算符
Here, we will learn how to declare, read and print dynamically allocated array?
在这里,我们将学习如何声明,读取和打印动态分配的数组?
A dynamic array declares by new operator and deletes by delete operator.
动态数组由new运算符声明,由delete运算符删除 。
Here we will read total number of elements, read total elements and print them.
在这里,我们将读取元素总数,读取元素总数并进行打印。
Consider the following program:
考虑以下程序:
#include <iostream>
using namespace std;
int main()
{
int *arr;
int i,n;
cout<<"Enter total number of elements:";
cin>>n;
//declare memory
arr=new int(n);
cout<<"Input "<<n<<" elements"<<endl;
for(i=0;i<n;i++)
{
cout<<"Input element "<<i+1<<": ";
cin>>arr[i];
}
cout<<"Entered elements are: ";
for(i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
delete (arr);
return 0;
}
输出量 (Output)
Enter total number of elements:5
Input 5 elements
Input element 1: 10
Input element 2: 20
Input element 3: 30
Input element 4: 40
Input element 5: 50
Entered elements are: 10 20 30 40 50
翻译自: https://www.includehelp.com/code-snippets/cpp-program-to-declare-read-and-print-dynamic-integer-array.aspx
c#读取整数空格