c/c++基础,你能做对多少?
Jee44 2007-10-09 04:39:33 无聊,空想的几个题目:)
欢迎大家讨论
1. int i=2;
int j = i++*i++;
int k = ++i*++i;
int l = i++*++i;
int m = ++i*i++;
j,k,l,m的值分别是什么?
2. test.h的内容为:
static int v;
void f();
test.cpp的内容为:
#include "test.h"
void f(){v=1;}
main.cpp的内容为:
#include "test.h"
void main()
{
v = 3;
f();
printf("%d\n", v);
}
这输出结果是什么?
4. class B{public:virtual int f();};
class B1:public B{public:virtual int f();};
class B2:public B{public:virtual int f();};
class B12要同时继承自B1、B2,实例化B12时要用到B1的方法f,该如何实现?有几种实现方式?
如果f都没virutal修饰符还能实现吗?
5. class B {
virutual int f();
int f();
}
这声明有问题吗?为什么?
6. 试实现class B使得以下代码能顺利编译
void print_str(const char *s)
{
printf("print_str: %s\n",s);
}
void print_int(int i)
{
printf("print_int: %d\n",i);
}
void main()
{
B b;
print_str("abc"+b);
print_int(++b+b++);
}