展讯笔试题目
10-16 00:00:09
来源:http://www.qz26.com 笔试题目 阅读:8632次
导读:{ //使用断言来检验输入参数的有效性。assert((strDest!=NULL) && (strSrc !=NULL)); char *address = strDest; while( (*strDest++ = * strSrc++) != ‘\0’ ) NULL ; return address ;}6。求两个字符串的最大公共字符子串,如"abccade","dgcadde"的最大子串为"cad"int GetCommon(char *s1, char *s2, char **r1, char **r2){ int len1 = strlen(s1); int len2 = strlen(s2); int maxlen = 0; for(int
展讯笔试题目,标签:银行笔试题目,企业笔试题目,http://www.qz26.com
{
//使用断言来检验输入参数的有效性。
assert((strDest!=NULL) && (strSrc !=NULL));
char *address = strDest;
while( (*strDest++ = * strSrc++) != ‘\0’ )
NULL ;
return address ;
}
6。求两个字符串的最大公共字符子串,如"abccade","dgcadde"的最大子串为"cad"
int GetCommon(char *s1, char *s2, char **r1, char **r2)
{
int len1 = strlen(s1);
int len2 = strlen(s2);
int maxlen = 0;
for(int i = 0; i < len1; i++)
{
for(int j = 0; j < len2; j++)
{
if(s1 == s2[j])
{
int as = i, bs = j, count = 1;
while((as + 1 < len1 )&& (bs + 1 < len2) && (s1[++as] ==s2[++bs]))
count++;
if(count > maxlen)
{
maxlen = count;
*r1 = s1 + i;
*r2 = s2 + j;
}
}
}
}
关于内存的4个经典题目GetMomery
void GetMemory(char *p) www.qz26.com
{
p = (char *)malloc(100);
}
{
//使用断言来检验输入参数的有效性。
assert((strDest!=NULL) && (strSrc !=NULL));
char *address = strDest;
while( (*strDest++ = * strSrc++) != ‘\0’ )
NULL ;
return address ;
}
6。求两个字符串的最大公共字符子串,如"abccade","dgcadde"的最大子串为"cad"
int GetCommon(char *s1, char *s2, char **r1, char **r2)
{
int len1 = strlen(s1);
int len2 = strlen(s2);
int maxlen = 0;
for(int i = 0; i < len1; i++)
{
for(int j = 0; j < len2; j++)
{
if(s1 == s2[j])
{
int as = i, bs = j, count = 1;
while((as + 1 < len1 )&& (bs + 1 < len2) && (s1[++as] ==s2[++bs]))
count++;
if(count > maxlen)
{
maxlen = count;
*r1 = s1 + i;
*r2 = s2 + j;
}
}
}
}
关于内存的4个经典题目GetMomery
void GetMemory(char *p) www.qz26.com
{
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
GetMemory(str);
strcpy(str, "hello world");
printf(str);
}
请问运行Test函数会有什么样的结果?
答:程序崩溃。
因为GetMemory并不能传递动态内存,
Test函数中的 str一直都是 NULL。
strcpy(str, "hello world");将使程序崩溃。
说的简单一些,就是传入的就是一个空指针,p确实分配空间了,
但是生成的空间首地址没有返回给str
2:
char *GetMemory(void)
{
char p[] = "hello world";
return p;
}
void Test(void)
{
char *str = NULL;
str = GetMemory();
printf(str);
}
请问运行Test函数会有什么样的结果?
Tag:笔试题目,银行笔试题目,企业笔试题目,求职笔试面试 - 笔试题目
下一条:中国农业银行总行笔试权威参考资料