嵌入式面試題1

來源:互聯網
上載者:User
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 63.編寫程式交換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++;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.