A. const char *pContent; //pContent 是指针,指向的是const char
B. char * const pContent;//pContet 首先是一个const 的变量,然后是一个指针,也就是说是一个const 的指针,指向char
C. char const *pContent;//和A一样,因为const 可以放在类型前,也可以放在类型后
D. const char* const pContent;
5. What is the output of the follow code? void main(int argc, char* argv[]) { int i = 11; int const *p = &i; p++; cout<<*p<<endl; } A. 11 B. 12 C. Garbage value D. Comipler error E. None of above Choose: C
一定要仔细!!
Which of the following C++ code is correct:
(A)
int f()
{
int *a = new int ( 3 );
return *a;
}
有内存泄露问题
(B)
int* f()
{
int a[ 3 ] = { 1, 2, 3 };
return a;
}
//局部变量
(C)
vector<int> f()
{
vector<int> v( 3 );
return v;
}
(D)
void f( int* ret )
{
int a[ 3 ] = { 1, 2, 3 };
ret = a;
return;
}
//ret 是指针,形参对于指针而言,是值传递。对于f(a),a的值不发生任何变化
//另外要注意,int a[3] = new int [3]是错误的,一定要用指针
(E)
none of above