@BruceWang
2018-10-19T08:53:47.000000Z
字数 3158
阅读 1336
王抒伟
# define ClrRegBit456(x) ?
Example:
ClrRegBit456(REG_A) ;
Ans:
#define ClrRegBit456(x) ((x)&0xFFFFFFC7)
void allocate_mem(char *str)
{
Str = (char*) malloc(100);
}
void test()
{
char*str = NULL;
allocate_mem(str);
strcpy(str, "Hello World");
printf(str);
}
Ans:
void allocate_mem(char **str)
{
*str = (char*) malloc(100);
}
void test()
{
char*str = NULL;
allocate_mem(&str);
strcpy(str, "Hello World");
printf(str);
free(str);
}
unsigned char a;
unsigned short b;
unsigned int c;
unsigned long d;
unsigned long long e;
unsigned int* p1, p2;
std:: cout() << sizeof(a) << " " << sizeof(b) " " << sizeof(c) << " " << sizeof(d) << " " << sizeof(e) << " " << sizeof(p1) << " " << sizeof(p2) <<
std::end1;
Complied and run by 32bit complier
Complied and run by 64bit complier
指针位数只和编译器的位数有关。
32位机器不能实现8位整数运算,longlong 其实是扩展。
64位机器可以实现8位整数运算,所以longlong 下放到long。
complier | char | short | int | long | long long | int* p1, p2 |
---|---|---|---|---|---|---|
32 | 1 | 2 | 4 | 4 | 8 | 4, 4 |
64 | 1 | 2 | 4 | 8 | 8 | 8, 4 |
unsigned char a = 128;
unsigned int b = ( a << 8 ) & ( a++ ) || (++a);
Ans:
#include <iostream>
using namespace std;
int main()
{
unsigned char a = 128;
unsigned int b = ( a << 8 ) & ( a++ ) || (++a);
printf("%d\n", a);
printf("%d", b);
return 0;
}
Output:
a = 130
b = 1
Ans: 一家自动驾驶AI公司---纵目科技软件、算法笔试题
The following questions just need choose any two of them.
void * Alloc64Aligned (int nSize)
void Free64Aligned ( void * p )
Ans:
void * Alloc64Aligned (int nSize){
char *ret;
int block;
int offset;
int i;
if (size<=0){
return NULL;
}
block=1+size/8;
ret=(char *)malloc(block*8);
offset=((unsigned long)ret)%8;
ret[0]=0;
for (i=1;i<8-offset;++i){
ret[i]=1;
}
return ret+8-offset;
}
void Free64Aligned ( void * p ){
char *buf;
int i;
if (p==NULL){
return ;
}
buf=(char *)p;
for (i=1;i<8;++i){
if (*(buf-i)==0){
break;
}
}
free(buf-i);
}
有一对兔子,从出生后第3个月起每生一对兔子,小兔子长到第三个月后又生一对兔子,假设兔子都不死,问第n个月兔子的总数为多少?
Int CalculateRabbitCount(int monthNum)
Ans:
int CalculateRabbitCount(int monthNum){
int temp[32];
int i;
temp[0]=1;
temp[1]=1;
for (i=2;i<monthNum;++i){
temp[i]=temp[i-1]+temp[i-2];
}
return temp[monthNum-1];
}
rand函数是已知库函数, 可以返回0到1之间的一个浮点数
array 是输入的一个递增数组, size是数组的长度。 函数返回时的结果也存在array的数组中。
float rand(); // return random value, 0 <= random value < 1
void random_sort(int* array, int size)
Ans:
//// T.3
void random_sort(int* array, int size){
int i;
int p;
int e;
for (i=0;i<size-1;++i){
p=(int)(rand()*(size-i));
e=array[i];
array[i]=array[i+p];
array[i+p]=e;
}
}
void bilinear_interpotation(unsigned char* src_buf,
int src_width,
int src_height,
unsigned char* dst_buf,
int dst_width,
int dst_height)
Ans:
不会。。。