| 【问题1】比较下面两段程序的优缺点。 ①for (i=0; i<N; i++ ) { if (condition) //DoSomething … else //DoOtherthing … } ②if (condition) { for (i =0; i<N; i++ ) //DoSomething }else { for (i=0; i <N; i++ ) //DoOtherthing … } |
| 【问题2】 下面的程序各自独立,请问执行下面的四个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); } } |