所以我试图为我的程序使用动态数组,我不知道我是否做得对。我应该使用 const int 还是仅使用 int ?
int size = 1;
int *num1 = new int [size];
int *num2 = new int [size];
Run Code Online (Sandbox Code Playgroud)
或者
const int size = 1;
int *num1 = new int [size];
int *num2 = new int [size];
Run Code Online (Sandbox Code Playgroud) 所以我从别处看到了一个程序,声明在主函数之外。就像这段代码:
#include<iostream>
using namespace std;
int num1, num2;
int *ptr1 = &num1, *ptr2 = &num2;
char operation, answer;
char *ptrop = &operation;
int main(){
}
Run Code Online (Sandbox Code Playgroud)
但是我现在使用的是在 main 函数中,如下所示:
#include<iostream>
using namespace std;
int main(){
int num1, num2;
int *ptr1 = &num1, *ptr2 = &num2;
char operation, answer;
char *ptrop = &operation;
Run Code Online (Sandbox Code Playgroud)
那么与它有什么区别呢?