學嵌入式找工作,面試最重要,下面是我在文思海輝公司面試時遇到的一些c開發面試題,都是我之前面試時見過的,很常見,都可以看看給自己充充電。
1.關于結構的大小,以下描述正確的有()
struct A_S struct B_S
{ {
unsigned short us1; unsigned char uc1;
unsigned short us2; unsigned int uc2;
unsigned short us3; unsigned short us3;
}; };
struct C_S struct D_S
{ {
unsigned int ui1 unsigned char uc2;
unsigned char uc2; unsigned short us3;
unsigned short us3; unsigned int ui1;
}; };
A.結構struct A_S的大小是6
B.結構struct B_S的大小是12
C.聯合union C_U的大小是12
D.聯合union D_U的大小是12
2.關于以下代碼,描述正確的有()
代碼Ⅰ: 代碼Ⅲ
const char * pcStr=”abcdefg”; char*pcStr=”abcdefg”
pcStr[3]=”a”;
代碼Ⅱ:
void string_sizeof(char szStr1[10]) 代碼Ⅳ
{ unsigned int uiA=100;
char szStr2[10]=”12345”; printf(“%s\r\n,”, uiA);
printf(“%u,”, sizeof(szStr1));
printf(“%u\r\n,”, sizeof(szStr2));
return;
}
Int main( )
{
string_ sizeof =(”12345”);
return 0;
}
A. 代碼Ⅰ,const修飾符表明pcStr指針不能再次被賦值,也就是說不能指向其他緩沖區.
B. 代碼Ⅱ,程序的運行結果是“4,10”.
C. 代碼Ⅲ,對pcStr[3]的賦值會導致程序訪問非法地址.
D. 代碼Ⅳ,打印unsigned int時不應該使用“%s”,會導致程序訪問非法地址。
3.以下語句中,能夠判斷uiNum(unsigned int)可以被8整除的有( )
A、If (((uiNum / 8)*8)== uiNum)
B、if ((uiNum % 8)== 1)
C、if ((uiNum &θ×θ7) ==θ)
D、if (((uiNum >> 3) << 3 )==uiNum )
編程題
數據的節點定義如下面的tagData所列,該數據節點有兩個索引值,分別是index1和index2,請編寫程序,有如下要求:
1)據上下文,由于需要分別以index1和index2索引查找,請建立兩個單向鏈表,分別以index1和index2,索引值唯一,且均為從小到大
2)提供增加節點的函數和刪除節點的操作,請注意增加和刪除節點的操作均會影響這兩個鏈表。
3)刪除操作數據是依據index2刪除的
/*節點數據*/
typedef struct tagData
{
Int index1;
Int index2;
Int iData;
}NODE_S;
/*Description:鏈表初始化*/void init( );
/*De scription:加入節點*/void add( int index1,int index2,int iData);
/*De scription:刪除節點*/void delete( int index2 );
請寫冒泡排序算法,a指向數組第一個元素,n為數組長度
Bubble_sort(int*a,int n)