关于C++动态数组的若干问题

#include <iostream>
using namespace std;

int f(int n)
{
    char x[n];
    x[0] = 'a';
    //测验了下长度为sizeof(类型)*n 
    cout<<"数组长度:"<<sizeof(x)<<endl; 
    return x[0];
}
int main()
{
    int a;
    cin>>a;
    cout<<f(a)<<endl;
    while(1);
    return 0;
}

//dev编译运行都没问题,不禁让我想起了是否可在main外new动态数组(长度在main内指定,长度也是全局),如今看来可以的

 

posted @ 2012-12-15 22:51  加拿大小哥哥  阅读(273)  评论(0)    收藏  举报