class B { public: B() { cout << "default constructor" << endl; } ~B() { cout << "destructed" << endl; } B(int i) :data(i) { cout << "constructed by parameter" << data << endl; } private: int data; }; B Play(B b) { return b; } int _tmain(int argc, _TCHAR* argv[]) { //下列结果是什么 B temp = Play(5); //Play(5); getchar(); return 0; } 第二题: main 主函数执行完毕后,是否可能会再执行一段代码,给出说明? 答案:可以,可以用_onexit 注册一个函数,它会在main 之后执行 int fn1(void), fn2(void), fn3(void), fn4 (void); void main( void ) { String str("zhanglin"); _onexit( fn1 ); _onexit( fn2 ); _onexit( fn3 ); _onexit( fn4 ); printf( "This is executed first. " ); } int fn1() { printf( "next. " ); return 0; } int fn2() { printf( "executed " ); return 0; } int fn3() { printf( "is " ); return 0; } int fn4() { printf( "This " ); return 0; } 第三题 如何打印出当前源文件的文件名以及源文件的当前行号? 答案: cout << __FILE__ ; cout<<__LINE__ ; __FILE__和__LINE__是系统预定义宏,这种宏并不是在某个文件中定义的,而是 由编译器定义的。 常见笔试/面试题目 2005 年 人在江湖 zhanglin@sjtu.edu.cn 1.已知strcpy 函数的原型是: char *strcpy(char *strDest, const char *strSrc); 其中strDest 是目的字符串,strSrc 是源字符串。不调用C++/C 的字符串库函数, 请编写函数 strcpy 答案: char *strcpy(char *strDest, const char *strSrc) { if ( strDest == NULL || strSrc == NULL) return NULL ; if ( strDest == strSrc) return strDest ; char *tempptr = strDest ; while( (*strDest++ = *strSrc++) != ‘