---
# System prepended metadata

title: 廣達電腦openBMC 2024/11
tags: [面試]

---

## 面試時間:2024/11
### 1.What are the outputs of following program?
```
#include <stdio.h>
#define PRINT_BOOL(condition) printf("%s\n", (condition)?"true":"false")

void quiz1 (int x){
    int i;
    int a=0x01;
    int b=0x04;
    
    PRINT_BOOL(a & b);
    PRINT_BOOL(a && b);
    
    for(i=0; i<4; i++)
        PRINT_BOOL(a<<i==b);
    
    x=(x|1);
}

void quiz2(int *x){
    char c='B'+255;
    printf("%c\n", c);
    
    *x=(*x|2);
}

void quiz3(int x){
    struct item{
        short val;
        struct item *next;
    }items[]={
        {5,&items[1]},
        {6,&items[2]},
        {7,&items[0]},
    };
    struct item *ptr;
    
    printf("%d\n", items[2].next->next->val);
    
    ptr=items[0].next;
    printf("%d\n", ptr->val);
    
    ptr=ptr+1;
    printf("%d\n", ptr->val);
    
    printf("%d\n", sizeof(items[0].val));
    printf("%d\n", sizeof(items[0].next));
    printf("%d\n", sizeof(struct item));
    
    x=(x|4);
}

void quiz4 (int *x){
    *x =(*x|8);
    printf("%d\n", *x);
}

int main (int argc, char **argv){
    int x=0;
    
    printf("\nQ1\n");
    quiz1(x);
    printf("\nQ2\n");
    quiz2(&x);
    printf("\nQ3\n");
    quiz3(x);
    printf("\nQ4\n");
    quiz4(&x);
    
    return 0;
}
```
* Ans:
```
Q1
false
true
false
false
true
false

Q2
A

Q3
6
6
7
2
4
8

Q4
10
```
