艰难的面试经历

 面试题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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值