阅读下面程序:
include<iostream.h>
void fun1(char a,char b)
{
char c;
c=a;a=b;b=c;
}
void fun2(char&a,char&b)
{
char c;
c=a;a=b;b=c;
}
void main()
{
char a,b;
a='x';b='y';
fun1(a,b);cout<<a<<b;
a='x';b='y';
fun2(a,b);cout<<a<<b;
}
则该程序的输出为______。
第1题:
下列程序的运行结果是______。
include<iostream.h>
class Base
{
public:
void f(int x){cout<<“Base:”<<x<<endl;}
);
class Derived:public Base
{
public:
void f(char*str){cout<<“Derived:”<<str<<endl;}
};
void main(void)
{
Base*pd=ne
第2题:
设有以下函数:
void fun(int n,char*$s){……}
则下面对函数指针的定义和赋值均正确的是
A.void(*pf)( );pf=fun;
B.void*Pf( );pf=fun;
C.void*pf( ); *pf=fun;
D.void(*pf)(int,char);nf=&fun;
第3题:
设有以下函数
void fun(int n,char * s) { …… }
则下面对函数指针的定义和赋值均是正确的是
A)void (*pf)(); pf=fun;
B)viod *pf(); pf=fun;
C)void *pf(); *pf=fun;
D)void (*pf)(int,char);pf=&fun;
第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 *GetMemory(void){ char p[] = "hello world";return
p; }void Test(void){char *str = NULL;str = GetMemory(); printf(str);}请问运行 Tes
t 函数会有什么样的结果?
第6题:
设有以下函数: void fun(int n,char*s){…} 则下面对函数指针的定义和赋值均正确的是( )。
A.void(*pf)( );pf=fun;
B.void*pf( );pf=fun
C.void*pf( );*pf=fun;
D.void(*pf)(int,char);pf=&fun;
第7题:
char*getmemory(void)
{ char p[]=”hello world”;
return p;
}
void test(void)
{
char *str=null;
str=Getmemory();
printf(str);
} 请问运行 Test 函数会有什么样的结果.
第8题:
下面程序的结果是( )。#include<iostream.h>void main(){char *str;str="test!";cout<<str[5];}
A.程序错误
B.!
C.'\0'
D.为空字符
第9题:
设有以下函数:
voidfun(intn,char}s){……}
则下面对函数指针的定义和赋值均正确的是( )。
A.void(*pf)(int,char);pf=&fun;
B.void+pf( );pf=fun;
C.void*pf( );*pf=fun;
D.void(*pf)(int,char*);pf=fun;
第10题:
分析下面的程序,指出程序中的错误: # include <stdio.h> int main(void) { char a; char *str=&a; strcpy(str,"hello"); printf("%sn",str); return 0; }