---
# System prepended metadata

title: 群聯面試
tags: [Interviews]

---

# 群聯面試

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

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

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

## [群聯三題](https://m033010041.github.io/2020/02/18/phison-interview-practice/)

## 面試
1. [local, static, global](/6E8YJc3vTj640nADvPvB0A)
2. [const, volatile](/6E8YJc3vTj640nADvPvB0A)
3. stack, heap 差別
https://pjchender.dev/computer-science/cs-stack-heap/
5. function, ISR 差別
https://www.geeksforgeeks.org/difference-between-isr-and-function-call/
7. function set bit, clear bit
9. (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
10. 依照順序填入 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.
```c
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
 
2.    Try to write a function that will set value “0xaa55” in the memory address of “0x1234”

```cpp=
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

3.    What is the output of the following code?
```CPP=
    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**
 
4.           
a. write a function to get bit18 value of an unsigned integer data and return 0 or 1.
```cpp=
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.
```cpp=
int set_18thbit(unsigned int n)
{
    return n |(1<<17);
}
```
c. write a function to clear bit18 value of an unsigned integer data.
```cpp=
int clear_18thbit(unsigned int n)
{
    return n & ~(1<<17);
}
```
 d. write a function to check the unsigned integer value is power of 2
```cpp=
bool IsPowerOfTwo(unsigned int x)
{
    return (x != 0) && ((x & (x - 1)) == 0);
}
```

6.  What is the result?
```CPP=
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 = 101, *p2 = 102
int f = ++*p3; // f = *p2 + 1 = 102 + 1

cout << "e =" << e << endl; // 101
cout << "f =" << f << endl; // 103
```
**ANS : 101, 2, 103, 4, 5, 6**


<以下兩題見Leetcode>

5. [字串反轉](https://leetcode.com/problems/reverse-string/)
> 補充：leetcode的func argument有string size，但先前面試經驗，需用指針實作strlen
8. [linked list找中點](https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list/)


## Other questions
[Excecise 1](https://www.dcard.tw/f/tech_job/p/238789639?cid=cab3300c-7a4e-4b5a-b533-2887ec512e51&fbclid=IwAR3fgbzke8Q2VeLGF4GMcC9YSKAYjCVWE_3JO_WvDAJp-9WFqwDD4jkFWcY)

[Exercise 2](https://creteken.pixnet.net/blog/post/24524138)