- 1. 输出什么?
- int a = (1,2);
- printf("a=%d\n",a);
- 答:a=2,逗号表达式的赋值
- 2. struct value {
- char a[3];
- short b;
- };
- struct value temp;
- printf("sizeof(temp) is %d\n", sizeof(temp));
- 答:sizeof(temp) is 6
- 3.编写程序交换a,b的值(使用二种方法)
- void swap(int *a, int *b)
- {
- int temp;
- temp = *a;
- *a = *b;
- *b = temp;
- }
- void swap(int *a, int *b)
- {
- *a = *a + *b;
- *b = *a - *b;
- *a = *a - *b;
- }
- 4. 说明int *p[5]和int(*p)[5]的区别
- 答:int *p[5]是指针数组,数组里存储的是指针
- (*p)[5]是数组指针,指向一个含有5个数的数组
- 5. 编写函数实现链表的创建,节点的插入和删除
- typedef struct node
- {
- int num;
- struct node *next;
- }Node;
- Node *create()
- {
- Node *p, *head;
- int n;
- head = (Node *)malloc(sizeof(Node));
- head->next = NULL;
- scanf("%d", &n);
- while(n > 0) {
- p = (Node *)malloc(sizeof(Node));
- p->num = n;
- p->next = head->next;
- head->next = p;
- scanf("%d", &n);
- }
- return head;
- }
- Node *insert(Node *head, int pos, int num)
- {
- Node *p, *pre;
- int i=1;
- pre = head;
- while(pre->next && i < pos)
- {
- pre = pre->next;
- i++;
- }
- p = (Node *)malloc(sizeof(Node));
- p->num = num;
- p->next = pre->next;
- pre->next = p;
- return head;
- }
- Node *delete(Node *head, int num)
- {
- Node *p, *pre;
- p = head->next;
- while(p->num != num) {
- pre = p;
- p = p->next;
- }
- if (p->num == num) {
- pre->next = p->next;
- free(p);
- }
- return head;
- }
- 6. 说明如下两片代码的区别
- char *p = "love linux";
- char p[] = "love linux";
- 答:*p中的p是一个指针,指向一片只读的字符串
- p[] 是一个数组,该数组被初始化
- 7.用C语言实现一相n!函数(要求用递归实现)
- long fact(int n)
- {
- if (n==0 || n==1) {
- return 1;
- }
- if(n > 1) {
- return n*fact(n-1);
- }
- }
- 8. char c;
- char b[20] = "I love Linux";
- c = 'I'与C=“I” 有什么区别,字符串b在内存占几个字节
- 答:c = 'I'是一个字符,c = "I" 是一个字符串,从对数组b的定义
- 可知,b在内存中占有20个字节(与它进行初始化的字符串长度无关)
- 9. 实现自己的mystrcat()函数
- char *mystrcat(char *dst, const char *src)
- {
- char *cp;
- cp = dst;
- while (*cp)
- cp ++;//指针指向字符串尾
- while(*cp++ = *src++);//每次循环最后一次拷贝了"\0"
- return dst;
- }
- 10. char str[20];
- scanf("%s", str);
- printf("%s", str);
- 如果输入I love linux回车,结果输出什么?为什么?
- 答:输出I,因为scanf输入字符串不能有空格
- 11. 已知两个整型数组均为升序排列,将两个数组合并,且合并后仍按升序排序
- //m为数组a的长度,n为数组b的长度,c是指向新开辟的数组
- void combin(int *a, int *b, int *c, int m, int n)
- {
- int *p1, *p2, *p3;
- for(p1 = a, p2 = b, p3 = c; p1 < a+m && p2 < b+n;)
- {
- if (*p1 < *p2)
- *p3++ = *p1++;
- else
- *p3++ = *p2++;
- }
- while(p1 < a+m) *p3++ = *p1++;
- while(p2 < b+n) *p3++ = *p2++;
- }
嵌入式面试题1
最新推荐文章于 2024-09-21 21:34:35 发布