. void Test(void) { char *str = (char *) malloc(100); strcpy(str, “hello”);
. void Test(void) { char *str = (char *) malloc(100); strcpy(str, “hello”); free(str); if(str != NULL) { strcpy(str, “world”); 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 函数会有什么样的结果?
试题4:
void GetMemory(char *p )
{
p = (char *) malloc(100 );
}
void Test(void )
{
char *str = NULL;
GetMemory(str );
strcpy(str, "hello world" );
printf(str );
}
试题5:
char *GetMemory(void )
{
char p[] = "hello world";
return p;
}
void Test(void )
{
char *str = NULL;
str = GetMemory();
printf(str );
}
阅读下列代码 public class Test 2005{ public static void main(String args[]){ System.out.println((3>2)?4:5); } } 其运行结果是
A.2
B.3
C.4
D.5
阅读下面程序
class Test implements Runnable{
public static void main(String[] args){
Test t = new Test();
t.start();
}
public void run(){ }
}
下列关于上述程序的叙述正确的是
A) 程序不能通过编译,因为 start() 方法在 Test 类中没有定义
B) 程序编译通过,但运行时出错,提示 start() 方法没有定义
C) 程序不能通过编译,因为 run() 方法没有定义方法体
D) 程序编译通过,且运行正常
下列代码的执行结果是()。 public class Test { public static void main(String args[]) { int a=4,b=6,c=8; String s="abc"; System.out.println(a+b+s+c); System.out.println(); } }
A.ababcc
B.464688
C.46abc8
D.10abc8
下列程序test类中的变量e的最后结果为()。 public class test { public static void main (String args[]) { int a=10; int b; int c; if(a>50) { b=9; } c=b+a; } }
A.10
B.0
C.19
D.编译出错
A.test(5);
B.test(5,8);
C.test(6,’#’);
D.test(0,0,’x’);
下列代码的输出结果是()。
class parent
{
void printme()
{
System.out.println("parent");
}
}
class child extends parent
{
void printme()
{
System. out.println("child");
}
void printall()
{
super, printme();
this.printme();
printme();
}
}
public class test
{
public static void main(String args[])
{
child myc=new child();
myc.printall();
}
}
A.import java.awt.*;
B.import java.applet.applet;
C.import java.io.*;
D.import java, awt.graphics;
在oneMethod()方法运行正常的情况下,程序段将输出什么? public void test(){ try { oneMethod(); System.out.println("condition 1"); } catch (ArrayIndexOutOfBoundsException e){ System.out.println("condition 2"); } catch(Exception e){ System.out.println("condition 3"); } finally { System.out.pritln("finally"); } }
A.condition 1
B.condition 2
C.condition 3
D.condition 1
A.5238.41Bh
B.5238.4,Bh
C.5,238.4,B,h
D.5238.41Bh