1、一个学生的信息是:姓名,学号,性别,年龄等信息,用一个链表,把这些学生信息连在一起, 给出一个age, 在些链表中删除学生年龄等于age的学生信息。
 程序代码
#i nclude "stdio.h"
#i nclude "conio.h"
struct stu{
char name[20];
char sex;
int no;
int age;
struct stu * next;
}*linklist;
struct stu *creatlist(int n)
{
int i;
//h为头结点,p为前一结点,s为当前结点
struct stu *h,*p,*s;
h = (struct stu *)malloc(sizeof(struct stu));
h->next = NULL;
p=h;
for(i=0;i<n;i++)
{ 
s = (struct stu *)malloc(sizeof(struct stu));
p->next = s;
printf("Please input the information of the student: name sex no age \n");
scanf("%s %c %d %d",s->name,&s->sex,&s->no,&s->age);
s->next = NULL;
访问固定的内存位置(Accessing fixed memory locations) C\C++ Development
10. 嵌入式系统经常具有要求程序员去访问某特定的内存位置的特点。在某工程中,要求设置一绝对地址为0x67a9的整型变量的值为0xaa66。编译器是一个纯粹的ANSI编译器。写代码去完成这一任务。
这一问题测试你是否知道为了访问一绝对地址把一个整型数强制转换(typecast)为一指针是合法的。这一问题的实现方式随着个人风格不同而不同。典型的类似代码如下: 
int *ptr; 
ptr = (int *)0x67a9; 
*ptr = 0xaa55;
一个较晦涩的方法是: 
*(int * const)(0x67a9) = 0xaa55;
即使你的品味更接近第二种方案,但我建议你在面试时使用第一种方案。
中断(Interrupts)
11. 中断是嵌入式系统中重要的组成部分,这导致了很多编译开发商提供一种扩展—让标准C支持中断。具代表事实是,产生了一个新的关键字__interrupt。下面的代码就使用了__interrupt关键字去定义了一个中断服务子程序(ISR),请评论一下这段代码的。
__interrupt double compute_area (double radius) 
{ 
double area = PI * radius * radius; 
printf(" Area = %f", area); 
return area; 
}
这个函数有太多的错误了,以至让人不知从何说起了: 
1). ISR 不能返回一个值。如果你不懂这个,那么你不会被雇用的。 
2). ISR 不能传递参数。如果你没有看到这一点,你被雇用的机会等同第一项。 
3). 在许多的处理器/编译器中,浮点一般都是不可重入的。有些处理器/编译器需要让额处的寄存器入栈,有些处理器/编译器就是不允许在ISR中做浮点运算。此外,ISR应该是短而有效率的,在ISR中做浮点运算是不明智的。 
4). 与第三点一脉相承,printf()经常有重入和性能上的问题。如果你丢掉了第三和第四点,我不会太为难你的。不用说,如果你能得到后两点,那么你的被雇用前景越来越光明了。
代码例子(Code examples)
12 . 下面的代码输出是什么,为什么?
void foo(void) 
{ 
unsigned int a = 6; 
int b = -20; 
(a+b > 6) puts("> 6") : puts("<= 6"); 
}
这个问题测试你是否懂得C语言中的整数自动转换原则,我发现有些开发者懂得极少这些东西。不管如何,这无符号整型问题的答案是输出是“>6”。原因是当表达式中存在有符号类型和无符号类型时所有的操作数都自动转换为无符号类型。 因此-20变成了一个非常大的正整数,所以该表达式计算出的结果大于6。这一点对于应当频繁用到无符号数据类型的嵌入式系统来说是丰常重要的。如果你答错了这个问题,你也就到了得不到这份工作的边缘。
13. 评价下面的代码片断:
unsigned int zero = 0; 
unsigned int compzero = 0xFFFF; 
/*1's complement of zero */
对于一个int型不是16位的处理器为说,上面的代码是不正确的。应编写如下:
unsigned int compzero = ~0;
这一问题真正能揭露出应试者是否懂得处理器字长的重要性。在我的经验里,好的嵌入式程序员非常准确地明白硬件的细节和它的局限,然而PC机程序往往把硬件作为一个无法避免的烦恼。 
到了这个阶段,应试者或者完全垂头丧气了或者信心满满志在必得。如果显然应试者不是很好,那么这个测试就在这里结束了。但如果显然应试者做得不错,那么我就扔出下面的追加问题,这些问题是比较难的,我想仅仅非常优秀的应试者能做得不错。提出这些问题,我希望更多看到应试者应付问题的方法,而不是答案。不管如何,你就当是这个娱乐吧…
动态内存分配(Dynamic memory allocation)
14. 尽管不像非嵌入式计算机那么常见,嵌入式系统还是有从堆(heap)中动态分配内存的过程的。那么嵌入式系统中,动态分配内存可能发生的问题是什么?
这里,我期望应试者能提到内存碎片,碎片收集的问题,变量的持行时间等等。这个主题已经在ESP杂志中被广泛地讨论过了(主要是 P.J. Plauger, 他的解释远远超过我这里能提到的任何解释),所有回过头看一下这些杂志吧!让应试者进入一种虚假的安全感觉后,我拿出这么一个小节目:下面的代码片段的输出是什么,为什么?
char *ptr; 
if ((ptr = (char *)malloc(0)) == NULL) 
puts("Got a null pointer"); 
else 
puts("Got a valid pointer"); 
这是一个有趣的问题。最近在我的一个同事不经意把0值传给了函数malloc,得到了一个合法的指针之后,我才想到这个问题。这就是上面的代码,该代码的输出是“Got a valid pointer”。我用这个来开始讨论这样的一问题,看看被面试者是否想到库例程这样做是正确。得到正确的答案固然重要,但解决问题的方法和你做决定的基本原理更重要些。
Typedef
15. Typedef 在C语言中频繁用以声明一个已经存在的数据类型的同义字。也可以用预处理器做类似的事。例如,思考一下下面的例子: 
#define dPS struct s * 
typedef struct s * tPS; 
以上两种情况的意图都是要定义dPS 和 tPS 作为一个指向结构s指针。哪种方法更好呢?(如果有的话)为什么? 
这是一个非常微妙的问题,任何人答对这个问题(正当的原因)是应当被恭喜的。答案是:typedef更好。思考下面的例子: 
dPS p1,p2; 
tPS p3,p4;
第一个扩展为 
struct s * p1, p2;
上面的代码定义p1为一个指向结构的指,p2为一个实际的结构,这也许不是你想要的。第二个例子正确地定义了p3 和p4 两个指针。
晦涩的语法
16. C语言同意一些令人震惊的结构,下面的结构是合法的吗,如果是它做些什么? 
int a = 5, b = 7, c; 
c = a+++b;
这个问题将做为这个测验的一个愉快的结尾。不管你相不相信,上面的例子是完全合乎语法的。问题是编译器如何处理它?水平不高的编译作者实际上会争论这个问题,根据最处理原则,编译器应当能处理尽可能所有合法的用法。因此,上面的代码被处理成: 
c = a++ + b; 
因此, 这段代码持行后a = 6, b = 7, c = 12。 
如果你知道答案,或猜出正确答案,做得好。如果你不知道答案,我也不把这个当作问题。我发现这个问题的最大好处是:这是一个关于代码编写风格,代码的可读性,代码的可修改性的好的话题
What will print out?
main() 
{ 
char *p1=“name”; 
char *p2; 
p2=(char*)malloc(20); 
memset (p2, 0, 20); 
while(*p2++ = *p1++); 
printf(“%sn”,p2); 
}
Answer:empty string.
What will be printed as the result of the operation below:
main() 
{ 
int x=20,y=35; 
x=y++ + x++; 
y= ++y + ++x; 
printf(“%d%dn”,x,y); 
} 
Answer : 5794
What will be printed as the result of the operation below:
main() 
{ 
int x=5; 
printf(“%d,%d,%dn”,x,x< <2,x>>2); 
}
Answer: 5,20,1
What will be printed as the result of the operation below:
#define swap(a,b) a=a+b;b=a-b;a=a-b; 
void main()
{ 
int x=5, y=10; 
swap (x,y); 
printf(“%d %dn”,x,y); 
swap2(x,y); 
printf(“%d %dn”,x,y); 
} 
int swap2(int a, int b) 
{ 
int temp; 
temp=a; 
b=a; 
a=temp; 
return 0; 
}
Answer: 10, 5
10, 5 
What will be printed as the result of the operation below:
main()
{ 
char *ptr = ” Cisco Systems”; 
*ptr++; printf(“%sn”,ptr); 
ptr++; 
printf(“%sn”,ptr); 
} 
Answer:Cisco Systems
isco systems 
What will be printed as the result of the operation below:
main()
{ 
char s1[]=“Cisco”; 
char s2[]= “systems”; 
printf(“%s”,s1); 
} 
Answer: Cisco 
What will be printed as the result of the operation below:
main()
{ 
char *p1; 
char *p2; 
p1=(char *)malloc(25); 
p2=(char *)malloc(25); 
strcpy(p1,”Cisco”); 
strcpy(p2,“systems”); 
strcat(p1,p2); 
printf(“%s”,p1);
}
Answer: Ciscosystems
The following variable is available in file1.c, who can access it?:
static int average;
Answer: all the functions in the file1.c can access the variable.
WHat will be the result of the following code?
#define TRUE 0 // some code 
while(TRUE) 
{ 
// some code
}
Answer: This will not go into the loop as TRUE is defined as 0.
What will be printed as the result of the operation below:
int x; 
int modifyvalue() 
{ 
return(x+=10); 
} 
int changevalue(int x) 
{ 
return(x+=1); 
} 
void main()
{ 
int x=10; 
x++; 
changevalue(x); 
x++; 
modifyvalue(); 
printf("First output:%dn",x); 
x++; 
changevalue(x); 
printf("Second output:%dn",x); 
modifyvalue(); 
printf("Third output:%dn",x); 
}
Answer: 12 , 13 , 13
What will be printed as the result of the operation below:
main()
{ 
int x=10, y=15; 
x = x++; 
y = ++y; 
printf(“%d %dn”,x,y); 
} 
Answer: 11, 16
What will be printed as the result of the operation below:
main()
{ 
int a=0; 
if(a==0) 
printf(“Cisco Systemsn”); 
printf(“Cisco Systemsn”); 
} 
Answer: Two lines with “Cisco Systems” will be printed.
 



 
											





 
	    

 
	