面试题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
不用sizeof来求出系统的位数,是16位还是32位?
思路:是根据系统的位数用一个数进行测试!
源码:















总结:如果用sizeof的程序







为什么要用long的大小,来判断系统的字节的大小,因为这个和ALU有关。
在系统中怎么查看呢?用命令
在ubuntu下,内核是2.6.15,可以用命令查看宏定义

就可以查看当前系统的位数
面试题2
实现char *strstr(char *source ,char *dist)函数






















































