char s1[] = "";
char s2[] = "Hello World!";
char *p = s2;
char *q = NULL;
void *r = malloc(100);
请计算:
sizeof (s1) =
sizeof (s2) =
sizeof ( p ) =
sizeof ( q ) =
sizeof (r) =
|
char s1[10] = {'m', 'o', 'b', 'i', 'l'};
char s2[20] = {'A', 'N', 'S', 'I', '\0', 'C', '+', '+'};
char s3[6] = {'I', 'S', 'O', 'C', '+', '+'};
请计算:
strlen(s1) =
strlen(s2) =
strlen(s3) =
s2[8] =
|
void Func ( char str[100])
{
请计算:
sizeof( str ) =
}
|
请写出BOOL flag 与“零值”比较的if 语句:
|
请写出float x 与“零值”比较的if 语句:
|
请写出char *p 与“零值”比较的if 语句:
|
// 第一个
for (i=0; i<N; i++)
{
if (condition)
DoSomething();
else
DoOtherthing();
}
|
// 第二个
if (condition)
{
for (i=0; i<N; i++)
DoSomething();
}
else
{
for (i=0; i<N; i++)
DoOtherthing();
}
|
优点:
缺点:
|
优点:
缺点:
|
void GetMemory(char *p)
{
p = (char *)malloc(100);
}
void Test(void)
{
char *str = NULL;
GetMemory(str);
strcpy(str, "hello world");
printf(str);
}
请问运行Test函数会有什么样的结果?
答:
|
char *GetMemory(void)
{
char p[] = "hello world";
return p;
}
void Test(void)
{
char *str = NULL;
str = GetMemory();
printf(str);
}
请问运行Test函数会有什么样的结果?
答:
|
Void GetMemory2(char **p, int num)
{
*p = (char *)malloc(num);
}
void Test(void)
{
char *str = NULL;
GetMemory(&str, 100);
strcpy(str, "hello");
printf(str);
}
请问运行Test函数会有什么样的结果?
答:
|
void Test(void)
{
char *str = (char *) malloc(100);
strcpy(str, “hello”);
free(str);
if(str != NULL)
{
strcpy(str, “world”);
printf(str);
}
}
请问运行Test函数会有什么样的结果?
答:
|