下面小段程序,哪个是正确的:()
A: char * p = new char[10];p[0] = 'K'; delete [] p;
B: int *p = new int[25]; p[10] = 100; delete p
C: char * p = new int; p = 'a'; delete p;
D: int * p = new char[20];p = 'a'; delete p;
A: char * p = new char[10];p[0] = 'K'; delete [] p;
B: int *p = new int[25]; p[10] = 100; delete p
C: char * p = new int; p = 'a'; delete p;
D: int * p = new char[20];p = 'a'; delete p;
举一反三
- 以下关于数组动态分配与释放内存的正确代码是 A: int p[100] = new int[100] 和 delete p B: int *p = new int(100) 和 delete p C: int *p = new int[100] 和 delete []p D: int *p = new int(100) 和 delete []p
- char* p = new char(32);释放内存的语句是: A: delete &p; B: delete *p; C: delete [] p; D: delete <char> p;
- char* p = new char(32);释放内存的语句是: A: delete [] p; B: free(p) C: delete p; D: delete <char> p;
- char* p = new char(32);释放内存的语句是: A: delete [] p; B: free(p) C: delete p; D: delete <char> p;
- 如果函数声明形式为 void fun( char* a, int n, int&m );以下函数正确的调用的为( ) A: char str[10]; int *p, m; fun( str, m, p ); B: char *p = new char[10]; int n, m; fun( p, m, &n ); C: char *p = new char[10]; int n, m; fun( p, m, n ); D: char *p = new char[10]; fun( p, 5, 6 );