艱難的面試經曆

來源:互聯網
上載者:User
 面試題1:   
    不用sizeof來求出系統的位元,是16位還是32位?
    思路:是根據系統的位元用一個數進行測試!
    源碼:
   

#include <stdio.h>
int main(int argc,char *argv[])
...{
    unsigned int a= ~0;
    if(a>65536)
    ...{
        printf("system is 32 bit  ");
    }
    else
    ...{
        printf("system is 16 bit  ");
    }
    return 0;
}

    總結:如果用sizeof的程式
  

#include <stdio.h>
int main(int argc,char *argv[])
...{
    printf("system is bits %d  ",sizeof(unsigned long));
    return 0;
}

    為什麼要用long的大小,來判斷系統的位元組的大小,因為這個和ALU有關。
    在系統中怎麼查看呢?用命令
    在ubuntu下,核心是2.6.15,可以用命令查看宏定義
   

getconf WORD_BIT

    就可以查看當前系統的位元
   面試題2
    實現char *strstr(char *source ,char *dist)函數
   

/**//*
 * 要實現 char *strstr(char *,char *)功能
 * */
#include <stdio.h>
char *strstd(char *source,char *dist)
...{
    char *movesource,*movedist,*temp;
    int length=0,i=0;
    movesource=NULL;
    movedist=NULL;
    temp=dist;

    while(*temp++!='')
        length++;

    while(*source!='')
    ...{
        if(*source==*dist)
        ...{
            movesource=source;
            movedist=dist;
            while(*movedist!='')
            ...{
                if(*movedist==*movesource)
                ...{
                    movedist++;
                    movesource++;
                    i++;
                    if(i==length)
                    ...{
                        return source;

                    }
                }
                else
                ...{
                    return NULL;
                }
            }
        }
        source++;
        i=0;
    }
}
int main(int argc,char *argv[])
...{
    char *a="wangyong";
    char *b="dd";
    char *result;
    result=strstd(a,b);
    if(result!=NULL)
    printf("result==%s ",result);

}

    面試題3

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.