---
# System prepended metadata

title: 聯發科 線上C測驗 2023版

---

# 聯發科 線上C測驗 2023版

## C - 選擇題
### 1 
```
int funA(int &a,int b) //認知中C不能這樣用但選項中沒有compile error
{
    a = (a%7==0) ? (a/7):(a%7);
    b = (b%17==0) ? (b/17):(b%17);
    return a+b;
}

int main(int argc, char *argv[])
{
    int a=41;
    int b=61;
    int c=funcA(a,b);
    printf("%d %d",a,c);
    return 0;
}
```

ANS: 6,16

### 2
```
#include <stdio.h>
int func()
{
    static int i=5;
    if(--i)
    {
        func();
        printf("%d ",i);
    }
}
int main(int argc, char *argv[])
{
    func();
    return 0;
}
```

ANS: 0 0 0 0

### 3
```
void main()
{
    char str[20] = "ABCDEF";
    printf("%d %d",sizeof(str),strlen(str));

}
```

ANS: 20 6

### 4
```
#include <stdio.h>

int main()
{
    int a[10][20][30]={0};
    a[5][2][1] = 2;
    
    return 0;
    
    // which following will print the value 2?
    A. printf("%d",*(((a+5)+2)+1));
    B. printf("%d",***((a+5)+2)+1);
    C. printf("%d",*(*(*(a+5)+2)+1));
    D. None of these;
}
```

ANS: C

### 5
```
#define N 5
#define Y(n) ((N+1)*n)

int main()
{
    int z = 2*(N+Y(3+2));
    z = ?
}
```

ANS: 50

### 6
```

void main()
{
    int i,j,m,n;
    i=8;
    j=10;
    m=++i;
    n=j++;
    printf("%d,%d,%d,%d",i,j,m,n);
}
```

ANS: 9,11,9,10

### 7
```
#define num 100
int change()
{
#undef num
#define num 10
    return num;
}

int main()
{
    int a=0;
    printf("num = %d, ",num);
    a = change();
    printf("Sum = %d",num+a);
    getch();
    return 0;
}
```

ANS: num = 10, Sum = 20

### 8
```
#include <stdio.h>
void f(char**);
#define num 100

int main()
{
    char *argv[] ={"ab","cd","ef","gh","ij","kl"};
    f(argv);
    return 0;
}

void f(char **p)
{
    char *t;
    t = (p+= sizeof(int))[-1];
    printf("%s",t);
}
```

ANS: gh

## C - 填充題
### 1 請問sum為多少
```
#include <stdio.h>

int fun(int a,int *b)
{
    static int c=0;
    a += *b;
    *b += a;
    c += a + *b;
    return c;
}

int main() {
    int x,y,z,sum;
    x = 5;
    y = 7;
    x = fun(x,&y);
    z = fun(x,&y);
    sum = x + y + z; 
    printf("%d",sum);
    return 0;
}
```
ANS:250

### 2 請問output
```
#include <stdio.h>
#define THRD 0x8 

int main() {
    int ch = 26;
    if(ch & 0xF > THRD)
    {
        printf("MORE %d",ch & 0xF);
    }
    else
    {
        printf("LESS %d",ch & 0xF);
    }
    return 0;
}
```
ANS:LESS 10

### 3 請問output
```
#include <stdio.h>
#define INC(x) x*=2,x+=1

int main() {
    int i,j;
    for(i=0;i<5;++i)
    INC(j);
    printf("%d",j);
    return 0;
}
```
ANS:31

### 4 請問result,count
```
#include <stdio.h>
int count = 0;
int calc(int x)
{
    count++;
    return x>0 ? calc(x-1)+calc(x-2)+1 : 1;
}

int main() {
    int result = calc(5);
    printf("%d %d",result,count);
    return 0;
}
```
ANS:25 25

### 5 請問output
```
#include <stdio.h>
#include <string.h>
char src[] = "Hello World";
char dst[20];

int main() {
    strncpy(dst, src, sizeof(dst));
    printf(":%zu:", strlen(dst));
    memcpy(dst, src, 5);
    printf(":%zu:", strlen(dst));
    strncpy(dst, src, 5);
    printf(":%zu:", strlen(dst));
    return 0;
}
```
* ANS: ":11::11::11:"

### 6 請問output
```
#include <stdio.h>
void func(void)
{
    static int i=0;
    i++;
    printf("%d",i);
}
int main() {
    for(int a=0; a<8; a++)
    {
        func();
    }
    return 0;
}
```
 ANS: 12345678
 
### 7 請填1跟2
![](https://i.imgur.com/AXsk31F.png)


### 8 請問輸出
```
#include <iostream>

union MyUnion
{
    int a[2];
    char b[8];
};

int main() {
    MyUnion temp;
    temp.a[0] = 3406;
    std::cout << temp.b[0];
    return 0;
}
```
 ANS: N


## C++ - 選擇題

## C++ - 填充題


## 程式設計題
1. 回文判斷
陷阱:題目說輸出是"YES"跟"No"，要改成"YES"跟"NO"才會pass。(考的是FW的通靈嗎)


2. SWAP(bit operation方式)
陷阱:兩個輸出的值中間要用"\n"換行
