一,
What's wrong with the following statement? (6 points)
char *psz = "Hello world!";
char dst[1024];
memcpy( psz, dst, sizeof( psz) );这个什么问题?
二,
Analyse the following short program: (10 points)
#include "stdafx.h"#include < assert.h >
#ifdef _DEBUG
#define ASSERT(x) assert(x);
#else
#define ASSERT(x)
#endif // _DEBUG
int _tmain(int argc, _TCHAR* argv[]){ printf("hello"); int fDoIt = 0; if( fDoIt ) ASSERT( false ) printf("bye bye"); getchar(); return 0;}
What's wrong with it? What is the difference in output when building release and debug builds?哪里错了?
三,
Here is a short C++ program: (10 points) class CShape{public: CShape() {;} ~CShape() {;} virtual void Draw() { printf("Drawing...\n"); }}; class CSquare : public CShape{public: CSquare() { m_pData = new unsigned char[1024]; } ~CSquare() { delete[] m_pData; } void Draw() { printf("Drawing a square\n"); } private: unsigned char *m_pData;}; int _tmain(int argc, _TCHAR* argv[]){ CShape * pShape = new CSquare(); pShape->Draw(); delete pShape; return 0;} Can you find any problems with this program? If so, what, and how would you fix it?
求求大神帮我解答
What's wrong with the following statement? (6 points)
char *psz = "Hello world!";
char dst[1024];
memcpy( psz, dst, sizeof( psz) );这个什么问题?
二,
Analyse the following short program: (10 points)
#include "stdafx.h"#include < assert.h >
#ifdef _DEBUG
#define ASSERT(x) assert(x);
#else
#define ASSERT(x)
#endif // _DEBUG
int _tmain(int argc, _TCHAR* argv[]){ printf("hello"); int fDoIt = 0; if( fDoIt ) ASSERT( false ) printf("bye bye"); getchar(); return 0;}
What's wrong with it? What is the difference in output when building release and debug builds?哪里错了?
三,
Here is a short C++ program: (10 points) class CShape{public: CShape() {;} ~CShape() {;} virtual void Draw() { printf("Drawing...\n"); }}; class CSquare : public CShape{public: CSquare() { m_pData = new unsigned char[1024]; } ~CSquare() { delete[] m_pData; } void Draw() { printf("Drawing a square\n"); } private: unsigned char *m_pData;}; int _tmain(int argc, _TCHAR* argv[]){ CShape * pShape = new CSquare(); pShape->Draw(); delete pShape; return 0;} Can you find any problems with this program? If so, what, and how would you fix it?
求求大神帮我解答