问题 单项选择题

有以下程序:
#include <stdio.h>
#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] :"abedefg", * p;
p = str + strlen(str)/2+1;
f(p,p -2);
printf( "% s \n" ,str);
程序运行后的输出结果是( )。

A.abcdefg

B.gfedcba

C.gbcdefa

D.abedcfg

答案

参考答案:B

解析: 本程序的作用是将字符串str倒序。语句p=str+strlen(str)/2+1;将指针变量p指向字符’e’所在的存储单元,P-2指向字符,’c’所在的存储单元,在函数f中将这两个存储单元的内容交换,然后将f函数中指向字符’e’的指针变量s加1,指向字符’c’的指针变量t减1,继续将s和t指向的存储单元的内容进行交换,直到s指向的存储单元的内容为空为止。所以本题程序输出的结果是字符串"abcdefe”的倒序形式"gfedcba"。

单项选择题

After a day’s hard work, we need some sleep. During the sleep, the fatigue (疲劳) of the body disappears and recuperation (恢复) begins. The tired mind gathers new energy, and the memory improves: Some adults require little sleep; others need eight to ten hours in every twenty-four hours. Infants (婴儿) sleep sixteen to eighteen hours dally, the amount gradually diminishing as they grow older. Young students may need twelve hours; university students may need ten. A worker with a physically demanding job may also need ten, whereas an executive working under great pressure may manage on six to eight. Many famous people have little sleep. Napoleon Bonaparte, Thomas Edison and Charles Darwin apparently averaged only four to six hours a night.

Whatever your individual need, you can be sure that by the age of thirty you will have slept for a total of more than twelve years. By that age you will also have developed a sleep routine: a favorite hour, a-favorite bed, a favorite position, and a rule you need to follow in order to rest comfortably.

Investigators have tried to find out how long a person can go without sleep. Several people have reached more than 115 hours—nearly five days. Whatever the limit, it is absolute. Animals that kept awake for from five to eight days have died of exhaustion. The limit for human beings is probably about a week.

The amount of sleep required may()

A. tire an individual mind

B. help infants grow older

C. apply pressure on an executive

D. depend on an individual age

判断题