深圳MTK公司嵌入式软件工程师笔试真题
1.
#define pi 3.14
#define Area(R) pi*R*R
main()
{
int r1=5,r2=2;
double s=0;
s=Area(r1-r2);
printf("The area is %f",s);
}
求结果: The area is 3.700000
2.函数 int compare(int a,int b),定义为该函数的函数指针P:为 int(*p)(int,int);p= compare;
3.求输出结果
#include
void sub(char*s,int num)
{
int i ,j=num;
char t;
while(j-->1)
{
for(i=0;i
{
if(s[i]
{
t=s[i];
s[i]=s[i+1];
s[i+1]=t;
}
}
}
}
main()
{
char *s="CEAeded";
sub(s,6);
printf("%s\n",s)
}
输出结果:运行时程序崩溃,
//4**********************************************
//交换两个变量的值,不使用第三个变量,即a=3,b=5交换
//后b=3,a=5
unsigned char a=3,b=5;
//5**************************************************
#define N 100
void GetMemory1(char*p)
{
p=(char*)malloc(sizeof(char)*N);
strcpy(p,"Have a good day!");
}
char*GetMemory2(void)
{
char p[]="Have a good day!";
return p;
}
void main(void)
{
char*str1=NULL,*str2=NULL;
GetMemory1(str1);
GetMemory2(str2);
printf("\nstr1:%s",str1);
printf("\nstr2:%s",str2);