- 相關推薦
?低曅@招聘筆試題
1、10、10、4、4四個數(shù),怎么算出24點?
(10*10-4)/4=24
2、下列表達式在32位機器編譯環(huán)境下的值()
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指向的是一個字符型的數(shù)組空間,原來的代碼只是簡單的釋放了指向申請空間的指針,并沒有釋放申請的空間,容易造成內(nèi)存崩潰,
?低曅@招聘筆試題
,資料共享平臺
《?低曅@招聘筆試題》(http://www.stanzs.com)。回收用 new 分配的單個對象的內(nèi)存空間的時候用 delete,回收用 new[] 分配的一組對象的內(nèi)存空間的時候用 delete[]。
【?低曅@招聘筆試題】相關文章:
?低曅@招聘嵌入式開發(fā)筆試題06-24
工行校園招聘筆經(jīng)10-31
建行校園招聘筆經(jīng)10-29
維達國際校園招聘筆經(jīng)10-03
新浪校園招聘筆試題05-26
網(wǎng)站校園招聘筆試題08-08
微軟校園招聘筆試題06-07
網(wǎng)易校園招聘筆試題10-06
校園招聘筆試題目08-27