( 34 )有如下程序:
#include
using namespace std;
int main ()
{
char str[100],*p;
cout<< ” please input a string: ” ;
cin>>str;
p=str;
for ( int i =0;*p!= ” \0 ” ;p++, i ++ ) ;
cout<< i <<ENDL;
retum 0;
}
运行这个程序时,若输入字符串为
abcdefg abcd
则输出结果是
A ) 7
B ) 12
C ) 13
D ) 100
第1题:
设有如下函数定义,则输出结果为______。 char*fun (char*str) {char*p=str; while(*p) { if(*p>'d') continue; p++; } return p; } main() { printf("%s\n",fun("welcome!")); }
A.welcome!
B.come!
C.w
D.程序陷入死循环中
第2题:
下列程序中,正确的为______。
A.main() { int *pb=&b; float 1>=15.25; print f("%d\n" ,*pb); }
B.amin() { int a,*pa; a=10; *pa=a; prinffC%d",*pa); }
C.main() { char s[20]; char *ps=&s; scanf("%s",*p); printf("%s",*p); }
D.main() { char str[10]; int *ps=str[0]; str="abcdefg"; printf("%s",*p); }
第3题:
以下程序的输出结果是【 】。
include <stdio.h>
include <string.h>
char *fun(char *t)
{ char *p=t;
return (p+strlen(t)/2);
}
main()
{ char *str="abcdefgh";
str=ftm(str);
puts(str);
}
第4题:
下面的程序各自独立,请问执行下面的四个TestMemory 函数各有什么样的结果?
①void GetMemory(char * p)
{
p = (char * )malloc(100);
}
void TestMemory (void)
{
char *str = NULL;
GetMemory (str);
strcpy(str, "hello world");
prinff(str);
}
② char * GetMemory (void)
{
char p[ ] = "hello world";
return p;
}
void TestMemory (void)
{
char * str = NULL;
str = GetMemory( );
printf(str);
}
③void GetMemory(char * * p, int num)
{
* p = (char * )malloc(num);
}
void TestMemory (void)
{
char * str = NULL;
GetMemory(&str, 100);
strcpy( str, "hello" );
printf(sir);
}
④void TestMemory (void)
{
char *str = (char * )malloe(100);
strepy (str, "hello" );
free ( str );
if(str ! = NULL)
{
strepy( str, "world" );
printf(str);
}
}
第5题:
设有如下函数定义,则输出结果为_______。 char*fun(char*str) { char*p=str; while(*p) {if(*p>'d')continue; p++; } return p; } main() { printf("%s\n",fun("welcome!")); }
A.welcome
B.come!
C.w
D.程序进入死循环
第6题:
以下程序的输出结果是_[13]_______
#include <stdio.h>
#include <string.h>
char *fun(char *t)
{ char *p=t;
return(p+strlen(t)/2);
}
main()
{ char *str="abcdefgh";
str=fun(str);
puts(str);
}
efgh