發哥(聯發科)上機考題目整理
Benson Note
[分享]嵌入式經典面試題
D = 履歷投遞(內推)
D + 20 = 安排面試
D + 30 = 面試
D + 37 = offer get
寫出以下程式執行後之輸出結果
What are commonly put in the stack?
what's the output
what's the output ?
what's the output
What will be output of the following c program ?
What value does f() return ?
What does the following declaration mean?
What is the output on screen?
Can the code be compiled?
what is the initialized value individually?
Given a sorted integer array "a", we want to check whether the target number is in the interval of (0, 10) of array "a". How many loop iteration will this binary search runs at most
What is the output of the following code?
What's the output?
1. Explain "#error"
#error指示詞會在編譯時期發出使用者指定的錯誤訊息,然後結束編譯。
寫給編譯器看,常搭配 Cflag cplusplus flag 使用,在編譯的時候中斷錯誤,如果有找到 #error 則會發出致命錯誤,並且跳過進一步的編譯過程。
2. Explain "struct" and "union"
在存儲多個成員信息時,編譯器會自動給struct第個成員分配存儲空間,struct 可以存儲多個成員信息,而Union每個成員會用同一個存儲空間,只能存儲最後一個成員的信息。
都是由多個不同的數據類型成員組成,但在任何同一時刻,Union只存放了一個被先選中的成員,而結構體的所有成員都存在。
對於Union的不同成員賦值,將會對其他成員重寫,原來成員的值就不存在了,而對於struct 的不同成員賦值 是互不影響的。
註:在很多地方需要對結構體的成員變量進行修改。只是部分成員變量,那麼就不能用聯合體Union,因為Union的所有成員變量占一個內存。eg:在鍊表中對個別數值域進行賦值就必須用struct.
struct 的大小會根據成員決定,且按照城市中的定義擺放的順序在內存中排序,按照宣告的順序擺放 (注意 alignment),union 的大小由內部最大的那個資料型態來定義, union 會用同一個儲存空間儲存資料,只能儲存最後的一個成員信息
補充
typedef: 保留字, C 語言:typedef 的用法
3. Explain "volatile". Can we use "const" and "volatile" in the same variable? Can we use "volatile" in a pointer?
volatile 加在變數前面,指編譯器每次對該變數進行存取時都要立即更新,不應該對其做任何最佳化。
A記憶體為硬體的記憶體,
當程式執行時候,有些記憶體經過編譯器編譯後,會暫存CPU暫存記憶體中(B),
然而,程式執行時優先取得B區的暫存器的值
意思是B區有個test變數=1,A區也有一個test=1
但如果有天A區的暫存值test改變了,B區的test CPU暫存器沒有隨著編譯器更新,
就會造成程式錯誤, 若使用volatile, 程式就會永遠都從(A)記憶區塊中取得test變數
不會對test編出一個位置在B區,也不會去取得B區塊的CPU暫存器
4. the value of v?
5. the value of *(a+1)
and (*p-1)
*(a+1)
= 2(*p-1)
= undefined*(p-1)
= 5參考 int *p=(int *)(&a + 1)的理解 以及 一道试题引发的血案
6. write a code
7. Re-write
Ans
參考 difference between int *a[3] and int (*a)[3]? [duplicate]
8. Write a code that check the input is a multiple of 3 or not without using division or mod
通用算法 (This can use for any number)
9. Explain lvalue and rvalue
C語言中的lvalue, rvalue
10. the value of array a?
11. 保證 n 一定是 5 個數字之一,不使用 if ,請用認為最快的方式實作 main
12. 保證 n 一定是 5 個數字之一, 使用 if ,用認為最快的方式實做 main
13. 寫一個 function 可傳入正整數 N ,回傳 1+2+3+…+N 之和
14. reverse a string(good problem)
15. 寫一個"標準"巨集 MIN,這個巨集輸入兩個參數並返回比較小的一個 參考
16. 寫出一個 function 判斷輸入的數是 2 的次方
17. Write a MACRO to caculate the squre of integer a.
18. Write a function to find the middle field of singled-linked list without traverse whole list
19. Write a code to reverse the linked list.
20. Find the possible error
21. What is the possible error of below SQR function.
因為是 volatile ,所以會產生類次下面這樣的代碼
由於 *a 可能被意想不到的改變,所以 temp1 和 temp2 可能是不同的,導致返回的不是平方值。
22. 用預處理指令 #define 聲明一個常數,用以表明一年中有多少秒
23. bunch of question
24 實作一個矩陣相乘的 function
關鍵字static的作用是什麼?
這個簡單的問題很少有人能回答完全。在C語言中,關鍵字static有三個明顯的作用:
下述程式碼行為
問輸出
Ans
問輸出
問輸出
輸入 n 印出 n 層的直角三角形
不使用運算子 sizeof
算出結構大小
1. stdio.h -> <\stdio.h> 在哪一步發生
2. a=?
3. output?
不用 sizeof
算出 struct 的大小
數字一個一個丟進來 (沒有 sort) 輸出每次的中位數