概要:class lclass : public Bclass{public:lclass(int i , int j , int k) : Bclass(i , j){z = k;}int fun(){return (x+y+z)/3;}private:int z;};int main(void){lclass obj(2,4,10);Bclass p1 = obj;cout<Bclass &p2 = obj;cout<cout<Bclass *p3 = &obj;cout return 0;}输出结果:050512、如何减少频繁分配内存(malloc或者new)造成的内存碎片?(10分)13、请写出strchr的实现(10分)函数功能:找出在字符串str中第一次出现字符ch的位置,找到就返回该字符位置的指针(也就是返回该字符在字符串中的地址的位置),找不到就返回空指针(就是NULL)const char* strchr(const char* str , char ch)const char* strchr(const char* str , cha
2017年海康威视校园招聘笔试题,标签:笔试大全,http://www.88haoxue.com{
public:
lclass(int i , int j , int k) : Bclass(i , j)
{
z = k;
}
int fun()
{
return (x+y+z)/3;
}
private:
int z;
};
int main(void)
{
lclass obj(2,4,10);
Bclass p1 = obj;
cout<
Bclass &p2 = obj;
cout<
cout<
Bclass *p3 = &obj;
cout
return 0;
}输出结果:
0
5
0
5
12、如何减少频繁分配内存(malloc或者new)造成的内存碎片?(10分)
13、请写出strchr的实现(10分)
函数功能:找出在字符串str中第一次出现字符ch的位置,找到就返回该字符位置的指针(也就是返回该字符在字符串中的地址的位置),找不到就返回空指针(就是NULL)
const char* strchr(const char* str , char ch)
const char* strchr(const char* str , char ch)
{
char *p = NULL;
const char* s = str;
for( ; *s != '\0' ; ++s)
{
if(*s == ch)
{
p = (char *)s;
break;
}
}
return p;
}
const char* strchr(const char* str , char ch)
{
char *p = NULL;
const char* s = str;
for( ; *s != '\0' ; ++s)
{
if(*s == ch)
{
p = (char *)s;
break;
}
}
return p;
}
14、请写出冒泡排序法算法(20分)
void BubbleSort(int r[] , int n);
void BubbleSort(int r[] , int n)
{
int i , j , temp;
for(i = 0 ; i < n - 1 ; ++i)
{
for(j = 0 ; j < n-i-1 ; ++j)
{
if(r[j] > r[j + 1])
{
temp = r[j];
r[j] = r[j + 1];
r[j + 1] = temp;
}
}
}
}
void BubbleSort(int r[] , int n)
{
int i , j , temp;
for(i = 0 ; i < n - 1 ; ++i)
{
for(j = 0 ; j < n-i-1 ; ++j)
{
if(r[j] > r[j + 1])
{
temp = r[j];
r[j] = r[j + 1];
r[j + 1] = temp;
}
}
}
}
最新更新