为什么在 C++ 中无法动态分配数组,但下面的代码编译成功?在取消注释它显示错误的评论?
#include<iostream>
#include <string>
using namespace std;
int main()
{
string aa;
cin>>aa;
int a[aa.size()];// though allocating the array dynamically the compilation succeeded
cout<<"COMPILATION SUCCESS"<<endl;
/*char *p;
cin>>p;
int y=sizeof(p);
int b[y];
cout<<"COMPILATION ERROR"<<endl;
*/
/*
int tt;
cin>>tt;
int c[tt];// shows error
cout<<"ERROR";
*/
}