微软研究院笔试题目 1.#include #include class CBuffer { char * m_pBuffer; int m_size; publc: CBuffer() { m_pBuffer=NULL; } ~CBuffer() { Free(); } void Allocte(int size) { m_size=size; cBuffer buffer1; buffer1.SaveString(“Microsoft”); printf(buffer1.GetBuffer()); } } 找出Allocate, SaveString, main的错误。
2.打印“Welcome MSR Asia” #include #include char * GetName (void) { //To return “MSR Asia” String char name[]=“MSR Asia”; return name; } void main(int argc, char* argv[]) { char name[32]; //Fill in zeros into name for(int i=0;i<=32;i++) { name[1]=‘{post.content}‘; } //copy “Welcome” to name name=“Welcome”; //Append a blank char name[8]=”; //Append string to name strcat(name,GetName()); //print out printf(name); } 找出程序中的错误。
3.#include class A { public: void FuncA() { printf(“FuncA called\n”); } virtual void FuncB() { printf(“FuncB called\n”); } }; class B: public A { public: void FuncA() { A::FuncA(); printf(“FuncAB called\n”); } virtual void FuncB() { printf(“FuncBB called\n”); } }; void main(void) { B b; A *pa; pa=&b; A *pa2=new A; b.FuncA(); b.FuncB(); pa->FuncA(); pa->FuncB(); pa2->FuncA(); pa2->FuncB(); delete pa2; } What is the output of the above program? 4.#include #include int FindSubString(char* pch) { int count=0; char* p1=pch; while(*p1!=‘{post.content}’) { if(*p1==p1[1]-1) { p1++; count++; } else { break; } } int count2=count; while(*p1!=‘{post.content}’) { if(*p1!==p1[1]+1) { p1++; count2--; } else { break; } if(count2==0) return count; return 0; } void ModifyString(char* pText) { char* p1=pText; char* p2=p1; while(*p1!=‘{post.content}’) { int count=FindSubString(p1); if(count>0) { *p2++=*p1; sprintf(p2, “%I”, count); while(*p2!= ‘{post.content}’) { p2++; } p1+=count+count+1; } else { *p2++=*p1++; } } } void main(void) { char text[32]=“XYBCDCBABABA”; ModifyString(text); printf(text); } In the main() function, after ModifyString(text) is called, what’s the value of ‘text’?
|