首页 > 考试题库
题目内容 (请给出正确答案)
[主观题]

分析下面的程序: void GetMemory(char **p,int num) { *p=(char *)malloc(num); } int main()

分析下面的程序:

void GetMemory(char **p,int num)

{

*p=(char *)malloc(num);

}

int main()

{

char *str=NULL;

GetMemory(&str,100);

strcpy(str,"hello");

free(str);

if(str!=NULL)

{

strcpy(str,"world");

}

printf("\n str is %s",str);

getchar();

}

问输出结果是什么?希望大家能说说原因,先谢谢了

查看答案
答案
收藏
如果结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能还需要:
您的账号:
发送账号密码至手机
发送
安装优题宝APP,拍照搜题省时又省心!
更多“分析下面的程序: void GetMemory(char *…”相关的问题
第1题
下面的程序是对Buton的事件处理 btn.setOnClickListener(new OnClickListener() { public v
下面的程序是对Buton的事件处理 btn.setOnClickListener(new OnClickListener() { public v

oid onClick(View v) { Intent it = new Intent(MainActivity.this,SecondActivity.class); startActivity(it); } }); 执行结果是:

A.点击Button后,显示启动MainActivity

B.点击Button后,显示启动SecondActivity

C.点击Button后,创建一个隐式的Intent对象

D.点击Button后,创建一个Activity

点击查看答案
第2题
#i nclude void testf(int*p) { *p+=1; } main() { int

#i nclude

void testf(int*p)

{

*p+=1;

}

main()

{

int *n,m[2];

n=m;

m[0]=1;

m[1]=8;

testf(n);

printf("Data v alue is %d ",*n);

}

------------------------------

B)

#i nclude

void testf(int**p)

{

*p+=1;

}

main()

{int *n,m[2];

n=m;

m[0]=1;

m[1]=8;

testf(&n);

printf(Data v alue is %d",*n);

}

下面的结果是程序A还是程序B的?

Data v alue is 8

那么另一段程序的结果是什么?

点击查看答案
第3题
编译运行下面的程序,说法正确的有 :()。import java.io.*;public class A{public static void
编译运行下面的程序,说法正确的有 :()。

import java.io.*;

public class A{

public static void main(String[] x){

String s="1234567890abcdefghijklmnopq";

byte[] b=s.getBytes();

try{

File f=new File("B.txt");

FileOutputStream ut=new FileOutputStream(f);

out.write(b,10,10);

out.write(b,0,5);

}catch (IOException e){

System.out.println(e.getMessage());

}

}

}

A.抛出一个可以被捕获的IOException

B.程序编译正常,并在当前目录下生成文件B.txt,文件内容为abcdefghij12345

C.编译正常,但运行时出现错误

D.程序编译正常,但屏幕没有任何输出

点击查看答案
第4题
给定下面的代码片段:public void Test() {try {method();System.out.println("Hello Wor
给定下面的代码片段:

public void Test() {

try {

method();

System.out.println("Hello World");

}

catch (ArrayIndexOutOfBoundsException e)

{

System.out.println("Exception?");

}

catch(Exception e)

{

System.out.println("Exception1");

}

finally{

System.out.println("Thank you!");

}

}

如果函数method正常运行并返回,会显示下面的哪些信息?()

A.Hello World

B.Exception

C.Exception1

D.Thank you!

点击查看答案
第5题
下面的代码中有什么错误吗?_______ using System; class A { public virtual void F(){

下面的代码中有什么错误吗?_______

using System;

class A

{

public virtual void F(){

Console.WriteLine("A.F");

}

}

abstract class B:A

{

public abstract override void F();

}

点击查看答案
第6题
12 . 下面的代码输出是什么,为什么? void foo(void) { unsigned int a = 6; int b = -20; (a+b

12 . 下面的代码输出是什么,为什么?

void foo(void)

{ unsigned int a = 6;

int b = -20;

(a+b > 6) puts("> 6") : puts("<= 6");

}

点击查看答案
第7题
12 . 下面的代码输出是什么,为什么?void foo(void){unsigned int a = 6;int b = -20;(a+b > 6

12 . 下面的代码输出是什么,为什么?

void foo(void)

{

unsigned int a = 6;

int b = -20;

(a+b > 6) puts("> 6") : puts("<= 6");

}

点击查看答案
第8题
下面的代码中有什么错误吗?_______ using System; class A { public virtual void F(){ Conso

下面的代码中有什么错误吗?_______

using System;

class A

{

public virtual void F(){

Console.WriteLine("A.F");

}

}

abstract class B:A

{

public abstract override void F();

点击查看答案
第9题
回答下面的问题(6分) (1).Void GetMemory(char **p, int num) { *p = (char *)mallo

回答下面的问题(6分) (1).Void GetMemory(char **p, int num) { *p = (char *)malloc(num); } void Test(void) { char *str = NULL; GetMemory(&str, 100); strcpy(str, "hello"); printf(str); } 请问运行Test 函数会有什么样的结果?

点击查看答案
第10题
下面的代码有什么问题?void DoSomeThing(...){char* p;...p = malloc(1024); // 分配1K的空间i

下面的代码有什么问题?

void DoSomeThing(...)

{

char* p;

...

p = malloc(1024); // 分配1K的空间

if (NULL == p)

return;

...

p = realloc(p, 2048); // 空间不够,重新分配到2K

if (NULL == p)

return;

...

}

点击查看答案
退出 登录/注册
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改