輸出
?char s1[]="2kgames";
?char* s2[]={"2kgames" };
?char s3[20]="2kgames";
?sizeof(s1)==?
?sizeof(s2)==?
?sizeof(s3)==?
?strlen(s1)==?
?strlen(s3)==??
?<答案:8 4 20 7 7
?
2.輸出
class A
{
?? public:
???? A() {? p();? }
???? ~A(){? p(); }
???? virtual void p() {? q(); }
???? virtual void q() {? cout<<''A'' }
};
class B:public A
{
?? public:
???? B() {? p(); }
???? ~B() {? p(); }
???? void q() {? cout<<''B'' }
};
int main()
{
??? A* p=new B;
??? delete p;
}
答案:ABA
?
3. 用一個(gè)C語(yǔ)言表達(dá)式判斷一個(gè)數(shù)是否位2的N次冪。
答案:x == (((x ^ (~0x0)) + 1) & x)
?
4. 寫一個(gè)高性能的函數(shù)把一個(gè)int乘以9
答案:
int Multiply_9(int a)
{
?? return ((a<<3)+a);
}
?
5.請(qǐng)寫一個(gè)C函數(shù),若處理器是Big_endian的,則返回0;若是Little_endian的,則返回1
解答:
int checkCPU()
{
union w
{
int a;
char b;
} c;
c.a = 1;
return (c.b == 1);
}
?
6.int (* (*f)(int, int))(int)這里的f是什么?
答案:f是指針,指向一個(gè)參數(shù)為(int,int),返回值為一個(gè)指針的函數(shù)
這個(gè)返回的指針指向一個(gè)參數(shù)為(int),返回值為int的函數(shù)
我的筆試之二:思科篇
1.
?typedef struct
?{
??? char data[10];
?}T1;
?
?typedef struct
?{
??? T1* p;
??? char data[0];
?}T2;
?sizeof(T2)==?
?
答案:4
?
2.含N個(gè)元素的一個(gè)數(shù)組,數(shù)組的值的范圍是1~N-1,找出重復(fù)的那個(gè)值。
答案:
int array[N];
int FindRepeat(void)
{
?? int flag[N]={0};
?? int i;
?? for(i=0;i小于N;i++)//由于此論壇系統(tǒng)問(wèn)題直接有小于號(hào)出現(xiàn)顯示不正常,故此用漢字描述
?? {
????? if(flag[array[i]]==1)
???????? return array[i];
????? else
???????? flag[array[i]]=1;
?? }
}
3.下面哪些編譯通不過(guò)?
(A).
?? void T()
?? {
????? const int N=100;
????? int a[N];
????? a[2]=42;
?? }
(B).
?? void T()
?? {
????? *((int* const)0x23567890)=5;
?? }
?
(C).
?? char* fuc(void)
?? {
????? char a[4];
????? strcpy(a,"abcd");
????? return a;
?? }
?
答案:ABC都可以通過(guò)編譯。
我的筆試之三:趨勢(shì)科技篇
1. 找錯(cuò)誤
(1) void Test(const int v)
??? {
??????? int* p;
??????? p=v;
??? }
??? 答案:不能把非const指針指向const變量。應(yīng)該是:const int* p;
?
(2) void Test(const int& v)
??? {
??????? const int& p;
??????? p=v;
??? }
??? 答案:引用必須在定義的時(shí)候初始化。應(yīng)該是:const int& p=v;
?
2. 編程題,翻轉(zhuǎn)鏈表。
答案:
typedef struct node
{
?? int value;
?? struct node* next;
}SLink;
?
SLink* ReverseLink(SLink* h)
{
?? SLink* pre,*cur,*next;
?? pre=NULL;
?? cur=h;
?? next=cur->next;
?? while(next)
?? {
????? cur->next=pre;
????? pre=cur;
????? cur=next;
????? next=next->next;
?? }
?? return cur;
}
?
3.寫出輸出結(jié)果
class A
{
?public:
?? A()
?? {
????? f(0);
?? }
?? virtual void f(int n)
?? {
????? cout<<"A0:"<<?? }
?? virtual void f(int n) const
?? {
????? cout<<"A1:"<<?? }
?? virtual void f(char* s)
?? {
????? cout<<"A2:"<<?? }
};
class B:public A
{
? public:
??? void f(int n)
??? {
?????? cout<<"B0:"<<??? }
??? void f(char* s)
??? {
????? cout<<"B1:<<??? }
};
int main()
{
?? A* p;
?? const A* cp;
?? B b;
?? p=&b;
?? p->f(1);
?? p->f("test");
?? A().f(2);
?? cp=&b;
?? cp->f(2);
}
答案:
? A0:0
? B0:1
? B1:test
? A0:0
? A0:2
? A1:2
?
4. UTP(非屏蔽雙絞線)的傳輸距離是?
答案:100m
?
5.176.68.160.0/22的子網(wǎng)掩碼是:
答案:255.255.252.0
我的筆試之四:先鋒商泰篇
1.下面表達(dá)式正確的是:
A. char* const s="hello";
?? *s=''''''''w''''
B. char* const s="hello";
?? s="world";
C. const char* s="hello";
?? *s=''''''''w''''
D. const char* s="hello";
?? s="world";?
答案:D
?
2.下面表達(dá)式正確的是:
A. char* const s="hello";
?? *s=''''''''w''''
B. char* const s="hello";
?? s="world";
C. char s[]="hello";
?? *s=''''''''w''''
D. char s[]="hello";
?? s="world";
答案:C
?
3.寫出程序輸出結(jié)果:
?char t[]="abcdefghijklmno";
?t[12]=''/0''//這里本該也沒(méi)有這么多單引號(hào)
?int i=0;
?while(t[++i]!=''/0'')//這里也是
?{
??? printf("%c",t[i++]);
?}
?答案:bdfhjln
我的筆試之五--展訊篇
1. 編程求兩個(gè)字符串的最大公共字符串。
答案:
#include "stdio.h"
#include "string.h"
?
/* 函數(shù)功能:求兩個(gè)字符串的最大公共字符串 */
void CommonStr(char* str1,char* str2)
{
?char* s1,*s2;
?int i,j,k;????????? // i--最大公共字符串的長(zhǎng)度
?int len1;?????????? // j--子串s2的開始位置
?int len2;?????????? // k--子串s1的開始位置
?int p;
?len1=strlen(str1);
?len2=strlen(str2);
?if(len1
?{
??? s1=str2;
??? s2=str1;
??? len2=len1;
?}
?else
?{
??? s1=str1;
??? s2=str2;
?}
?for(i=len2;i>0;i--)?? // 從最大的開始找
?{
??? for(j=0;j+i<=len2;j++)
??? {
?????? for(k=0;k+i<=len1;k++)
?????? {
????????? p=0;
????????? while(s1[k+p]==s2[j+p])
????????? {
???????????? p++;
????????? }
????????? if(p>=i)
????????? {
???????????? for(p=0;p小于i;p++)
???? ?????????? printf("%c",s1[k+p]);
???????????? printf("/n");
???????????? return;
????????? }
?????? }
??? }
?}
}
int main(void)
{
?char* s1="worlld";
?char* s2="hello,cjw";
?CommonStr(s1,s2);
?return 0;
}
?
2.計(jì)算一個(gè)字節(jié)里1的個(gè)數(shù)。
方法一:
int Num_1(char data)
{
??? int i,j;
??? int sum=0;
??? j=1;
??? for(i=0;i<8;i++)
??? {
?????? j=1<
?????? if(data&j)
????????? sum++;
??? }
??? return sum;
}
方法二:
unsigned int FindOneInNumber_02(unsigned char x)
{
?? unsigned int n;
?? for(n=0; x; n++)
????? x &= x-1;
??? return n;
}