嵌入式软件开发——嵌入式软件工程师经典笔试题

C语言测试是招聘嵌入式系统程序员过程中必须而且有效的方法。这些年,我既参加也组织了许多这种测试,在这过程中我意识到这些测试能为面试者和被面试者提供许多有用信息,此外,撇开面试的压力不谈,这种测试也是相当有趣的。


预处理器(Preprocessor)


         #define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL
        #define MIN(A,B) ((A) <= (B) (A) : (B)) 

least = MIN(*p++, b);


死循环(Infinite loops)


while(1)

{

}
for(;;)
{

}
Loop:

goto Loop;
数据声明(Data declarations)






a) int a; // An integer 

b) int *a; // A pointer to an integer 
c) int **a; // A pointer to a pointer to an integer 
d) int a[10]; // An array of 10 integers 
e) int *a[10]; // An array of 10 pointers to integers 
f) int (*a)[10]; // A pointer to an array of 10 integers 
g) int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer 
h) int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and return an integer 
Static


Const


const int a;

int const a;
const int *a;
int * const a;
int const * a const;
Volatile



int square(volatile int *ptr)
{
        return *ptr * *ptr;
}

int square(volatile int *ptr) 

{
    int a,b;
    a = *ptr;
    b = *ptr;
    return a * b;
}

long square(volatile int *ptr) 


{
    int a;
    a = *ptr;
    return a * a;
}

位操作(Bit manipulation)


#define BIT3 (0x1 << 3)

static int a;

void set_bit3(void) 
{
    a |= BIT3;
}
void clear_bit3(void) 
{
    a &= ~BIT3;
}
访问固定的内存位置(Accessing fixed memory locations)


    int *ptr;

    ptr = (int *)0x67a9;
    *ptr = 0xaa55;
   *(int * const)(0x67a9) = 0xaa55;
中断(Interrupts)

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2015年6月26日
下一篇 2015年6月27日

相关推荐