电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

2025年计算机招聘笔试试题精华

2025年计算机招聘笔试试题精华_第1页
1/105
2025年计算机招聘笔试试题精华_第2页
2/105
2025年计算机招聘笔试试题精华_第3页
3/105
试题 6:void GetMemory( char **p, int num ){ *p = (char *) malloc( num );}void Test( void ){ char *str = NULL; GetMemory( &str, 100 ); strcpy( str, "hello" ); printf( str ); free(str); str=NULL;}答:malloc 后,应推断 *p 是否 NULL标准的 new 运算符在分配失败时,抛出一个 bad_alloc 类型的异常。在任何情况下,校验标准形式 new 运算符返回结果都不能起到检测错误的功效。void test(void) { char str = (char ) malloc(100) strcpy(str, "hello"); free(str); if(str != null) { strcpy(str “world”);//野指针 printf(str) } } 请问运行 test 函数会有什么样的结果? 篡改动态内存区的内容,后果难以预料,非常危险。 因为 free(str) 之后,str 成为野指针, if(str != null)语句不起作用。假如数组做函数形参,那么就蜕变为普通指针(不是指针常量),而且失去了常量性,可以被修改void test(char str[100]) { str++;}试题 7:编写类 String 的构造函数、析构函数和赋值函数答:class String { public: String(const char *str = NULL); String(const String &other); ~String(); String & operator= (const String &other); private: char *m_data;};String::String(const char *str) { if(str == NULL) { m_data = new char[1];//arrary new } else { m_data = new char[strlen(str) + 1]; strcpy(m_data, str); }}String::String(const String &other) { m_data = new char[strlen(other.m_data) + 1]; strcpy(m_data, other.m_data);}String::~String() { delete[] m_data;//array delete}String & String::operator= (const String &other) { if(this == &other) return (*this); delete[] m_data; m_data = new char[strlen(other.m_data) + 1]; strcpy(m_data, other.m_data); return (*this);}试题 8:请说出 C++中 static 和 const 关键字尽可能多的作用答:static 的作用:1)static 局部变量,作用域为本函数内,但是生存期是整个程序运行期,不同于 auto 变量,只初始化一次,下次调用时维持上次的值。2)static 全局变量,作用域为本文件内,生存周期是整个程序运行期3)static 全局函数,作用域为本文件内4)类的 static 成...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

2025年计算机招聘笔试试题精华

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部