答题前,请如实填写英语四六级考试成绩,未参加六级考试的,对应出不填. 英语四级考试成绩:520 英语六级考试成绩:
考试时间为1小时。
嵌入式篇
1.用变量a给出下面的定义
a)一个整型数int a;
b)一个指向整型数的指针int *a;
c)一个指向指针的的指针,它指向的指针是指向一个整型数int **a;
d)一个有10个整型数的数组int a[10];
e) 一个有10个指针的数组,该指针是指向一个整型数的。int *a[10];
f) 一个指向有10个整型数数组的指针int (*a)[10;]
g) 一个指向函数的指针,该函数有一个整型参数并返回一个整型数int (*a)(int);
h) 一个有10个指针的数组,该指针指向一个函数,该函数有一个整型参数并返回一
个整型数int (*a[10])(int);
2.用预处理指令#define 声明一个常数,用以表明1年中有多少秒(忽略闰年问题)。
#define SECONDS_PER_YEAR (60*60*24*365)UL
3.写一个"标准"宏MIN ,这个宏输入两个参数并返回较小的一个。
#define MIN(A,B) ((A)<=(B)?(A):(B))
4.定义一个全局变量intval = 10,写出在其他文件中引用此变量val的语句?
externval;
val=val++;
5.定义enum workday{mon, tue, wed,thu,fri};,请问thu = 3.
6.对typedef的用法举例。
typedefint(*p)();
p function(int (*a)());
7.请写出你知道的任意4个“位运算符”符号。
&、^、|、~、
8.局部变量能否和全局变量重名?
可以。
9.关键字static的作用是什么?
两个作用:1.局部变量被申明为static,表示这个函数结束的时候这个的值不变。
2.外部变量被申明为static表明它是一个本地全局变量。改变量只能在该文
件内被访问,不能被其它文件访问。
10.关键字volatile有什么含意?
被volatile定义的变量表示这个变量可能会产生意想不到的改变,这样定义之后编译器就不会去假设这个变量的值,也就是说在优化时提醒编译器每次都必须到内存中去取这个变量的值,而不是使用保存在寄存器的备份。
11.头文件中的ifndef/define/endif干什么用?
define 的作用是用一个指定的标示符代替已有的标示符,这个标示符可以有变量也可以没有变量
条件编译:他的作用是若所指定的标示符已经被#define命令定义过,则在程序编译阶段不编译define程序段
12.switch()中不允许的数据类型是?
除了整型和字符外其他的都不行
13.包含头文件的方法#include “xxx.h”和#include
前者表示这个xxx.h是程序开发者自己定义的头文件,后者表示是C库中存在头文件。
14.char * const p; char const * p;const char *p。这三个有什么区别?
char * const p;指向一个字符型的只读指针
char const * p;指向一个只读字符型变量的指针
const char *p指向一个只读字符型变量的指针
15.在32位系统中,有如下定义的对象,请问sizeof(object1)= 3字节,sizeof(object2)=
7字节,sizeof(object3)= 4字节
(1)char object1[] = “boy”;
(2)Struct item {
char a;
short b;
int c;
};
struct item object2;
(3)union item {
char a;
short b;
int c;
};
union item object3;
16.这段程序的输出是:( b )
main()
{
int a[5] = {1,2,3,4,5};
int *ptr = (int*)(&a+1);
printf("%d %d" , *(a+1), *(ptr-1) );
}
(a) 2 2
(b) 2 1
(c) 2 5
(d) 以上均不是
17.请完成函数fun(),计算n的阶乘n!(注:使用递归实现)。
unsigned long long fun(unsigned int n);
{
if(n==0)
return 1;
else
{
intrecurse=fun(n-1);
int result=n*recurse;
return result;
}
}
18.二者选一题(请选择如下任意一题作答)
(1)写一个函数sum(),计算1~100(包括100)之间数的累加和。
int sum()
{
inti,sum1;
for(i=0;i<101;i++)
{
sum1=sum1+i;
}
return(sum1);
}
(2)有一个16位的无符号整数,每4位为一个数,写函数求他们的和。
解释:
整数1101010110110111
和1101+0101+1011+0111
19.选做题(如有余力可对如下两题做答)
(1)写出程序把一个链表中的结点顺序倒排。
typedef struct linknode
{
int data;
structlinknode *next;
}node;
具体详细代码如下:
#include
#include
#include
typedefintDataType;
typedef struct linknode
{
DataType data;
structlinkode *next;
}node;
//---- initiate
voidListInitiate(node **head)
{
if( (*head=(node *)malloc(sizeof(node)))==NULL ) exit(1); elseprintf("OK\n");
(*head)->next=NULL;
}
//---- length cal
intListLength(node *head)
{
node *p=head;
int size=0;
while(p->next!=NULL){
p=p->next;
size++;
}
return size;
}
//----insert a node
intListInsert(node *head,inti,DataType x)
{
node *p,*q;
int j;
p=head;
j=-1;
while( (p->next!=NULL) && (j<(i-1)) ) {
p=p->next;
j++;
}
if(j!=(i-1)) {
printf("Position error\n");
return 0;
}
if((q=(node *)malloc(sizeof(node)))==NULL)
exit(1);
q->data=x;
q->next=p->next;
p->next=q;
return 1;
}
//----delete a node
intListDelete(node *head,inti,DataType *x)
node *p,*s;
int j;
p=head;
j=-1;
while((p->next!=NULL) && (p->next->next!=NULL) && (j
j++;
}
if(j!=i-1){
printf("Position error\n");
return 0;
}
s=p->next;
*x=s->data;
p->next=p->next->next;
free(s);
return 1;
}
//----- data get
intListGet(node *head,inti,DataType *x)
{
node *p;
int j;
p=head;
j=-1;
while((p->next!=NULL)&&(j
p=p->next;
j++;
}
if(j!=i) {
printf("Position error\n");
return 0;
}
*x=p->data;
return 1;
}
//----Destroy a chain
void Destroy(node **head)
{
node *p,*p1;
p=*head;
while(p!=NULL) {
p1=p;
p=p->next;
free(p1);
}
*head=NULL;
}
//-----converse a chain
void converse(node *head)
{
node *p,*q;
p=head->next;
head->next=NULL;
while(p!=NULL) {
q=p;
p=p->next;
q->next=head->next;
head->next=q;
}
}
//---- composite operation
int main(void)
{
node *head;
inti,x;
ListInitiate(&head);
for(i=0;i<10;i++) {
if(ListInsert(head,i,i)==0){
printf("Error\n");
return 1;
}
}
if(ListDelete(head,0,&x)==0) // chain,position,data address {
printf("Error\n");
return 1;
}
if(ListInsert(head,0,100)==0) {
printf("Error\n");
return 1;
}
converse(head);
for(i=0;i if(ListGet(head,i,&x)==0) // chain,position,data address { printf("Error\n"); return 1; } elseprintf("%d ",x); } printf("\n"); Destroy(&head); return 0; } /*------ E -------*/ (2)写出程序删除链表中的所有接点。 typedef struct linknode { int data; structlinknode *next; }node;