【面试题】数码视讯---2013校园招聘---笔试题

今天在北交大的笔试。小题就不记录了。

嵌入式C方向

三道大题是:

1,strcmp函数实现。

 

#include <iostream>
using namespace std;

int My_Strcmp(const char *p1,const char * p2)
{
	register const unsigned char *s1 = (const unsigned char *) p1;
	register const unsigned char *s2 = (const unsigned char *) p2;
	unsigned char c1, c2;
	do
	{
		c1 = (unsigned char) *s1++;
		c2 = (unsigned char) *s2++;
		if(c1 == '\0')
		{
			return c1 - c2;
		}
	}while (c1 == c2);
	return c1 - c2;
}

int __cdecl you_strcmp (const char * src,  const char * dst)  
{  
        int ret = 0 ;  
        while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)   
		{
			++src, ++dst;  
		}
        if ( ret < 0 )  
		{
			ret = -1 ;  
		}
        else if ( ret > 0 )  
		{
			ret = 1 ;     
		}
        return( ret );  
}  

int Yeah_strcmp(const char *pStr1, const char *pStr2)  
{  
    if(NULL == pStr1 && NULL == pStr2)  
    {  
        return 0;  
    }  
    while(('\0' != *pStr1) && ('\0' != *pStr2))  
    {  
        if(*pStr1 < *pStr2)  
        {  
            return -1;  
        }  
        else if(*pStr1 > *pStr2)  
        {  
            return 1;  
        }  
        else  
        {  
            ++ pStr1, ++ pStr2;  
        }  
    }  
    if(('\0' == *pStr1) && ('\0' == *pStr2))  
    {  
        return 0;  
    }  
    else if(('\0' == *pStr1) && ('\0' != *pStr2))  
    {  
        return -1;  
    }  
    else   
    {  
        return 1;  
    }  
} 

void main()
{
	char *a = "a";
	char *b = "ab";
	cout << My_Strcmp(a,b) <<endl;
	cout << you_strcmp(a,b) <<endl;
	cout << Yeah_strcmp(a,b) <<endl;
}


2,判断大段小段模式。

 

#include <iostream>
using namespace std;

int checkCPU()
{
	union w
    {
		int a;
        char b;
	}c;
    c.a = 1;
    return(c.b ==1);
}

void main()
{
	if(checkCPU())
	{
		cout << "小段模式"<<endl;
	}
	else
	{
		cout << "大端模式" <<endl;
	}
}


3,有序链表的创建。

你可能感兴趣的:(c,面试,null,招聘,DST)