群聯面試

歡迎大家自行新增考古題~ 有問題的地方也可以用 "建議修訂" 標註

考古

  1. 實做 C strlen, strcpy 等函式
  2. 指標++ & ++指標
    https://tclin914.github.io/e9206a47/
  3. 1470. Shuffle the Array
  4. 給一段遞迴code print 結果
  5. 20. Valid Parentheses
  6. linklist insert & array reverse
  7. 還有一些偏韌體ISR的問題
  8. 給一段binary search code 解釋

電訪

  1. n 是否為 power of 2
bool isPowerOf2(int a) { int tmp = a & (~a + 1); return tmp == a; }
  1. queue v.s. linkedlist
    https://stackoverflow.com/questions/48401777/what-is-the-difference-between-linkedlist-and-queue

群聯三題

面試

  1. local, static, global
  2. const, volatile
  3. stack, heap 差別
    https://pjchender.dev/computer-science/cs-stack-heap/
  4. function, ISR 差別
    https://www.geeksforgeeks.org/difference-between-isr-and-function-call/
  5. function set bit, clear bit
  6. (a & (a - 1) == 0x00) 什麼意思
    Ans : a is power of 2
    https://stackoverflow.com/questions/600293/how-to-check-if-a-number-is-a-power-of-2
  7. 依照順序填入 matrix
0 1
2 4
3 5
6 7
8 10
9 11

  1. Assuming that we are using 32-bit compiler, pointer in 4 bytes.
int array[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
int *ptr = (int *) (&array + 1);
int *ptr2 = array;

If the address of array is 200, try to answer the following questions:
(1) &array = 200
(2) &array + 1 = 240 //跨了一整個array 所以位址+10 * sizeof(int)
(3) ptr = 240 //依照宣告定義 所以同上
(4) *ptr = 未定義 //array的下一個位址的值是多少不知道
(5) ptr - 1 = 236
(6) *(ptr - 1) = 100 //array下一個位址往前一個位址後取值 即array的最後一個值
(7) *array = 10 //array取指標 隱性轉型 指向array第一個位址的值
(8) *array + 1 = 11
(9) *(array + 1) = 20
(10) ptr2 = 200 //指向array第一個位址
(11) *ptr2 = 10 //指向array第一個位址的值
(12) ptr2[1] = 20
(13) *(ptr2 + 1) =20

  1. Try to write a function that will set value “0xaa55” in the memory address of “0x1234”
int volatile * const p_reg = (int *) 0x1234; //set pointer to an address *p_reg = 0xaa55; // dereference to set the value

https://stackoverflow.com/questions/19133962/how-to-write-a-data-in-particular-address-in-c

  1. What is the output of the following code?
void change(int *a, int &b, int c) { c = *a; b = 3; *a = 2; return; } void main() { int a = 1, b = 2, c = 3; change(&a, b, c); printf(“%d %d %d”, a, b, c); return; }
​​​​ **ANS: 2,3,3**

a. write a function to get bit18 value of an unsigned integer data and return 0 or 1.

int get_18thbit(unsigned int n) { if(n &(1<<17)) { return 1; } else { return 0; } }

b. write a function to set bit18 value of an unsigned integer data.

int set_18thbit(unsigned int n) { return n |(1<<17); }

c. write a function to clear bit18 value of an unsigned integer data.

int clear_18thbit(unsigned int n) { return n & ~(1<<17); }

d. write a function to check the unsigned integer value is power of 2

bool IsPowerOfTwo(unsigned int x) { return (x != 0) && ((x & (x - 1)) == 0); }
  1. What is the result?
int a[] = {1,2,3,4,5,6}; int *p = a; *(p++) += 100; // postfix先做等號兩邊運算 再做括號內的運算 所以是p[0]+100 再位址+1到p[1] *(++p) += 100; //prefix先做括號內的運算 再做等號兩邊運算 所以先位址+1到p[2]再取值+100 for(int i = 0; i<6 ; i++) printf("%d ", a[i]); //補充 int *p2 = a; int *p3 = a; int e = (*p2)++; //e = *p = 1, 再e+1 但沒有e = e+1 所以++沒用 int f = ++*p3; //f = *p2 + 1 = 2 cout << "e =" << e << endl; cout << "f =" << f << endl;

ANS : 101, 2, 103, 4, 5, 6

<以下兩題見Leetcode>

  1. 字串反轉

補充:leetcode的func argument有string size,但先前面試經驗,需用指針實作strlen

  1. linked list找中點

Other questions

Excecise 1

Exercise 2