本文核心词:海康威视校招。
1、10、10、4、4四个数,怎么算出24点?
(10*10-4)/4=24
2、下列表达式在32位机器编译环境下的值()
class A
{
};
class B
{
public:
B();
virtual ~B();
};
class C
{
private:
#pragma pack(4)
int i;
short j;
float k;
char l[64];
long m;
char *p;
#pragma pack()
};
class D
{
private:
#pragma pack(1)
int i;
short j;
float k;
char l[64];
long m;
char *p;
#pragma pack()
};
int main(void)
{
printf(“%d\n”,sizeof(A));
printf(“%d\n”,sizeof(B));
printf(“%d\n”,sizeof(C));
printf(“%d\n”,sizeof(D));
return 0;
}
class A
{
};
class B
{
public:
B();
virtual ~B();
};
class C
{
private:
#pragma pack(4)
int i;
short j;
float k;
char l[64];
long m;
char *p;
#pragma pack()
};
class D
{
private:
#pragma pack(1)
int i;
short j;
float k;
char l[64];
long m;
char *p;
#pragma pack()
};
int main(void)
{
printf(“%d\n”,sizeof(A));
printf(“%d\n”,sizeof(B));
printf(“%d\n”,sizeof(C));
printf(“%d\n”,sizeof(D));
return 0;
}A、1、4、84、82 B、4、4、82、84 C、4、4、84、82 D、1、4、82、82
3、以下程序在32位机器下运行的结果是()
#pragma pack(4)
struct info_t
{
unsigned char version;
unsigned char padding;
unsigned char extension;
unsigned char count;
unsigned char marker;
unsigned char payload;
unsigned short sequence;
unsigned int timestamp;
unsigned int ssrc;
};
union info_u
{
unsigned char version;
unsigned char padding;
unsigned char extension;
unsigned char count;
unsigned char marker;
unsigned char payload;
unsigned short sequence;
unsigned int timestamp;
unsigned int ssrc;
};
#pragma pack()
int main(void)
{
printf(“%d\n”,sizeof(info_t));
printf(“%d\n”,sizeof(info_u));
return 0;
}
#pragma pack(4)
struct info_t
{
unsigned char version;
unsigned char padding;
unsigned char extension;
unsigned char count;
unsigned char marker;
unsigned char payload;
unsigned short sequence;
unsigned int timestamp;
unsigned int ssrc;
};
union info_u
{
unsigned char version;
unsigned char padding;
unsigned char extension;
unsigned char count;
unsigned char marker;
unsigned char payload;
unsigned short sequence;
unsigned int timestamp;
unsigned int ssrc;
};
#pragma pack()
int main(void)
{
printf(“%d\n”,sizeof(info_t));
printf(“%d\n”,sizeof(info_u));
return 0;
}A、12 12 B、12 4 C、16 4 D、16 12 E、16 1
4、以下表达式result的值是()
#define VAL1(a,b) a*b
#define VAL2(a,b) a/b–
#define VAL3(a,b) ++a%b
int a = 1;
int b = 2;
int c = 3;
int d = 3;
int e = 5;
int result = VAL2(a,b)/VAL1(e,b)+VAL3(c,d);
#define VAL1(a,b) a*b
#define VAL2(a,b) a/b–
#define VAL3(a,b) ++a%b
int a = 1;
int b = 2;
int c = 3;
int d = 3;
int e = 5;
int result = VAL2(a,b)/VAL1(e,b)+VAL3(c,d);A、-2 B、1 C、0 D、2
5、请写出以下程序的输出(5分)
void swap_1(int a , int b)
{
int c;
c = a;
a = b;
b = c;
return ;
}
void swap_2(int &a , int &b)
{
int c;
c = a;
a = b;
b = c;
return ;
}
void swap_3(int *a , int *b)
{
int c;
c = *a;
*a = *b;
*b = c;
return ;
}
int main(void)
{
int a = 100;
int b = 200;
swap_1(a , b);
printf(“a = %d , b = %d\n”,a , b);
swap_2(a , b);
printf(“a = %d , b = %d\n”,a , b);
swap_3(&a , &b);
printf(“a = %d , b = %d\n”,a , b);
return 0;
}
void swap_1(int a , int b)
{
int c;
c = a;
a = b;
b = c;
return ;
}
void swap_2(int &a , int &b)
{
int c;
c = a;
a = b;
b = c;
return ;
}
void swap_3(int *a , int *b)
{
int c;
c = *a;
*a = *b;
*b = c;
return ;
}
int main(void)
{
int a = 100;
int b = 200;
swap_1(a , b);
printf(“a = %d , b = %d\n”,a , b);
swap_2(a , b);
printf(“a = %d , b = %d\n”,a , b);
swap_3(&a , &b);
printf(“a = %d , b = %d\n”,a , b);
return 0;
}输出结果:
a = 100 , b = 200
a = 200 , b = 100
a = 100 , b = 200
6、下面的程序是否有问题,如有问题,请重构代码(5分)
void test_type(bool b , const char *p , float f)
{
if(!b)
{
return ;
}
else if(!p)
{
return ;
}
else if(!f)
{
return ;
}
}
void test_type(bool b , const char *p , float f)
{
if(!b)
{
return ;
}
else if(!p)
{
return ;
}
else if(!f)
{
return ;
}
}修改如下:
void test_type(bool b , const char *p , float f)
{
if(!b)
{
return ;
}
else if(!p)
{
return ;
}
else if(f > -1e-10 && f < 1e-10)
{
return ;
}
}
void test_type(bool b , const char *p , float f)
{
if(!b)
{
return ;
}
else if(!p)
{
return ;
}
else if(f > -1e-10 && f < 1e-10)
{
return ;
}
}7、请指出以下程序有什么问题(5分)
void test_mem()
{
char *p = new char[64];
delete p;
p = NULL;
return ;
}
void test_mem()
{
char *p = new char[64];
delete p;
p = NULL;
return ;
}应该修改为 delete[]p; p指向的`是一个字符型的数组空间,原来的代码只是简单的释放了指向申请空间的指针,并没有释放申请的空间,容易造成内存崩溃,
海康威视校园招聘笔试题
,
资料共享平台
《海康威视校园招聘笔试题》()。
回收用 new 分配的单个对象的内存空间的时候用 delete,回收用 new[] 分配的一组对象的内存空间的时候用 delete[]。
未经允许不得转载:全书网 » 海康威视校园招聘笔试题