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 函数会有什么样的结果?
第1题:
下列程序的运行结果为
#include<stdio.h>
void abc(char*str)
{ int a,b;
for(a=b=0;str[a]!='\0';a++)
if(str[a]!='c')
str[b++]=str[a];
str[b]='\0';}
void main()
{ char str[]="abcdef";
abc(str);
printf("str[]=%s",str); }
A.str[]=abdef
B.str[]=abcdef
C.str[]=a
D.str[]=ab
第2题:
下列程序运行后,如果从键盘上输入ABCDE<回车>,则输出结果为______。 #include<stdio.h> #include<string.h> fuch (char str[] ) { int num=0; while (*(str+num)!='\0')num++; return(num); } main() { char str[10],*p=str; gets(p);printf("%d\n",fuch(p)); }
A.8
B.7
C.6
D.5
第3题:
下列程序的运行结果为( )。 #include<stdio.h> void abc(char*str) { int a,b,i,j; for(i=j=0;str[i]!='\0';i++) if(str[i]!='a' str[j++]=str[i]; str[j]='\0'; } void main() { char str[]="abcdef"; abc(str); printf("str[]=%s",str); }
A.str[]=bcdef
B.str[]=abcdef
C.str[]=a
D.str[]=ab
第4题:
下列程序段的运行结果是( )。 #include<stdio.h> void main() { char str[]="ABC",*p=str; printf("%d\n",*(p+3)); }
A.67
B.0
C.字符'C'的地址
D.字符'C'
第5题:
以下程序运行后,如果从键盘上输入ABCDEF<回车>,则输出结果为______。 #include<stdio.h> #include<string.h> func(char str[]) { int num=0; while(*(str+num)!='\0') num++; return(num);p } main() { char str[10],*p=str; gets(p);printf("%d\n",func(P)); }
A.8
B.7
C.6
D.5
第6题:
以下程序运行后的输出结果是______。
include <iostream>
include <string>
using namespace std;
class Y;
class X
{
int x;
char *strx;
public:
X(int a, char *str)
{
x=a;
strx=new char[strlen(str)+1]
strcpy (strx,str);
}
void show(Y &ob);
};
class Y
{
prlvate:
int y;
char *stry;
public:
Y(int b,char *str)
{
y=b;
stry=new char[strlen(str)+1];
strcpy(stry,str);
}
friend void X::show(Y &ob);
};
void X::show{Y &ob)
{
cout<<strx<<",",
cout<<ob.stry<<endl;
}
int main{
{
X a (10, "stringX");
Y b (20, "stringY");
a. show (b);
renurn 0;
}
第7题:
char str[ ]= "Hello";
char *p=str;
int n=10;
sizeof(str)=( )
sizeof(p)=( )
sizeof(n)=( )
void func(char str[100])
{ }
sizeof(str)=( )
第8题:
char*getmemory(void)
{ char p[]=”hello world”;
return p;
}
void test(void)
{
char *str=null;
str=Getmemory();
printf(str);
} 请问运行 Test 函数会有什么样的结果.
第9题:
void GetMemory(char *p){p = (char *)malloc(100);}void Test(void) {char *str
= NULL;GetMemory(str); strcpy(str, "hello world");printf(str);}请问运行 Test 函数
会有什么样的结果?
第10题:
void Test(void){char *str = (char *)
malloc(100); strcpy(str, “hello”); free(str); if(str != NULL) { strcpy(str, “
world”); printf(str);}}请问运行 Test 函数会有什么样的结果?
第11题:
下列程序段的运行结果是( )。#include<stdio.h>void main(){ char str[]="ABC",*p=str; printf("%d\n",*(p+3));}
A.67
B.0
C.字符'C'的地址
D.字符'C'
第12题:
下列程序的输出结果是______。
include<iostream.h>
int CalcDigital(char*str)
{
if(str= =NULL)
return 0;
int num_of_digital=0;
for(int i=0;str{i]!=0x0;i++)
if(str[i]<='9'&& str[i]>='0')
num_of_digital++;
return num_of_digital;
}
void main( )
{
char a[]="Beijing20080lympic";
cout<<CalcDigital(a)<<endl;
}
第13题:
下列程序的运行结果为( )。
#include<stdio.h>
voidabc(char*str)
{int a,b,i,j;
for(i=j=0;str[i]!='\0';i++)
if(str[i]!='a')
str[j++]=str[j];
str[j]='\0';
}
void main()
{char Str[]="abcdef';
abc(str);
printf("str[]=%s",str);
}
A.str[]=bcdef
B.str[]=abcdef
C.str[]=a
D.str[]=ab
第14题:
以下C程序段的输出结果是(30)。 #include <stdio. h> void abc(char *str){ int a, b; for(a=b=0;str[a]!='\O';a++)if(str[a]!='c') str[b++]=str[a]; str[b]='\O'; } void main(){ char str[]="abcdef"; abc(str); printf("str[]=%s",str); }
A.str[]=a
B.str[]=ab
C.str[]=abdef
D.str[]=abcdef
第15题:
有以下程序: #include<string.h> void f(char *s,char *t) {char k; k=*s; +s=*t; *t=k; S++; t--; if(*s) f(s,t); } main() {char.str[10]="abcdefg",*p; p=str+strlen(str) /2+1; f(p,p-2); printf("%s\n",str); } 程序运行后的输出结果是 ______。
A.abcdefg
B.gfedcba
C.gbcdefa
D.abedcfg
第16题:
下列程序段的运行结果是( )。
#include<stdio.h>
void main()
{ char str[]="ABC",*p=str;
printf("%d\n",*(p+3) );
}
A.67
B.0
C.字符'C'的地址
D.字符'C'
第17题:
以下程序的输出结果是 ______。 #include<iostream.h> #include<string.h> void main(){ char *p1=",hello",*p2="world!",str[50]:"Hii"; strcpy(str+2,p1); strcat(str,p2); cout<<str; }
A.Hii,hello world!
B.hello world!
C.ii,hello world!
D.Hi,hello world!
第18题:
void setmemory(char **p, int num)
{ *p=(char *) malloc(num);}
void test(void)
{ char *str=NULL;
getmemory(&str,100);
strcpy(str,"hello");
printf(str);
}
运行test函数有什么结果?( )
第19题:
有关内存的思考题
1. void getmemory(char *p)
{ p=(char*)mallol(100);
}
void test(void)
{
char * str =null;
getmemory(str);
strcpy(str,”hello,world”);
printf(str);
}
请问运行 Test 函数会有什么样的结果
第20题:
以下为 Windows NT 下的 32位 C++程序,请计算 sizeof的值
char str[] = “Hello” ; char *p = str ;int n = 10;请计算 sizeof (str )
= sizeof ( p ) = sizeof ( n ) = void Func (
char str[100]){请计算 sizeof( str ) = }
void *p = malloc( 100 );请计算 sizeof ( p ) =
第21题:
char *GetMemory(void){ char p[] = "hello world";return
p; }void Test(void){char *str = NULL;str = GetMemory(); printf(str);}请问运行 Tes
t 函数会有什么样的结果?
第22题:
下面的程序各自独立,请问执行下面的四个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);
}
}
第23题:
下列程序的运行结果为 #include<stdio.h> vold abc(char*str) { int a,b; for(a=b=0;str[a]! ='\0';a++) if(str[a]!='c') str[b++]=str[a]; str[b]='\0';} void main() { char str[]="abcdef"; abc(str); printf("str[]=%s",str);}
A.str[]=abdef
B.str[]=abcdef
C.str[]=a
D.str[]=ab