{
// test1 char str[] = "world";
cout << sizeof(str) << ": ";
char *p = str;
cout << sizeof(p) << ": ";
char i = 10;
cout << sizeof(i) << ": ";
void *pp = malloc(10);
cout << sizeof(pp) << endl;
}
void main(void) {
int nArrLength(400), i = 546;
for (int i = 0; i< 99999999999; i++);
cout << nArrLength << endl;
cout << i << endl;
}
【标准答案】
void main(void) {
int nArrLength(400), i = 546;
/*主要是考看对C++的基础知识是否了解这里的int nArrLength(400)是对整数的定义,当然,明名上有问题,这里是故意这样的,
但是,最好是变量名改为 ....[还是您自己看着办了]*/ f
for (int i = 0; i< 99999999999; i++);
/*这里是考对变量越界理解,同时....,所以,999...应该改为 ~((int)0),也就是整数中0取反考对变量块作用域的理解,这里的i,在循环后就不存在了*/
cout << nArrLength << endl; // 这里输出 400
cout << i << endl; // 这里输出 546
}
int &max(int & x, int & y) {
return x > y? x : y;
}
int x = 55, y = 77;
max(x, y) += 12 + 11; // 此时 y = 92;
cout << "x = "x << "; y = "<< y << endl; // 输出 x = 55; y = 92;
int add_n(int n) {
static int i = 100;
i += n;
return i;
}
unsigned short array[]={1,2,3,4,5,6,7}; int i = 3;
*(array + i) =
long fn(long n) {
if(n <= 0) {
printf("error: n must > 0);
exit(1);
}
if(0 == n % 2)
return (n / 2) * (-1);
else
return (n / 2) * (-1) + n;
}
char str1[] = "abc";
char str2[] = "abc";
const char str3[] = "abc";
const char str4[] = "abc";
const char* str5 = "abc";
const char* str6 = "abc";
cout << boolalpha << ( str1==str2 ) << endl; // 输出什么?
cout << boolalpha << ( str3==str4 ) << endl; // 输出什么?
cout << boolalpha << ( str5==str6 ) << endl; // 输出什么?
【参考答案】
三元表达式“?:”问号后面的两个操作数必须为同一类型。
unsigned int const size1 = 2;
char str1[ size1 ];
unsigned int temp = 0;
cin >> temp;
unsigned int const size2 = temp;
char str2[ size2 ];
struct CLS
{
int m_i;
CLS( int i ) : m_i(i) {}
CLS()
{
CLS(0);
}
};
CLS obj;
cout << obj.m_i << endl;
int a=5, b=7, c;
c = a+++b;
【标准答案】a=6,b=7,c=12
void func() {
static int val; …
}
int a = 4;
(A)a += (a++); (B) a += (++a) ;
(C)(a++) += a;(D) (++a) += (a++);
a = ?
#include
const char *str = "vermeer";
int main()
{
const char *pstr = str;
cout << "The address of pstr is: " << pstr << endl;
}
inline void max_out( int val1, int val2 )
{
cout << ( val1 > val2 ) ? val1 : val2;
}
int main()
{
int ix = 10, jx = 20;
cout << "The larger of " << ix;
cout << ", " << jx << " is ";
max_out( ix, jx );
cout << endl;
}
【标准答案】