printf(str);
}
第1题:
阅读以下函数说明和C语言函数,将应填入(n)处的语句写在对应栏内。
【函数1.1说明】
本程序可以打印出如下图形(菱形):
*
***
*****
*******
*****
***
*
【函数2.1】
main()
{
int i,j,k;
for(i=0;i<=3;i++)
{
for(j=0;j<=2-i;j++)
printf(" ");
for((1))
printf("*");
printf("\n");
}
for(i=0;i<=2;i++)
{
for((2))
printf(" ");
for(k=0;k<=4-2*i;k++)
printf("*");
printf("\n");
}
}
【函数2.2说明】
通过本程序,可以从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件“CsaiWgm”中保存,输入的字符串以“!”结束。
【函数2.2】
include "stdio.h"
main()
{
FILE *fp;
char str[100],filename[10];
int i=0;
if((fp=fopen("CsaiWgm","w"))==NULL)
{
printf("cannot open the file\n");
exit(0);
}
printf("please input a string:\n");
gets(str);
while((3))
{
if(str[i]>='a'&&str[i]<='z')
str[i]=(4);
fputc(str[i],fp);
(5);
}
fclose(fp);
fp=fopen("CsaiWgm","r");
fgets(str,stden(str)+1,fp);
printf("%s\n",str);
fclose(fp);
}
第2题:
有以下程序: #include<string.h> main() { char str[][20]={"Hello","Beijing"),*p=str[0]; printf("%d\n",strlen(p+20)); } 程序运行后的输出结果是( )。
A.0
B.5
C.7
D.20
第3题:
下列程序段的运行结果是( )。
#include<stdio.h>
void main()
{ char str[]="ABC",*p=str;
printf("%d\n",*(p+3) );
}
A.67
B.0
C.字符'C'的地址
D.字符'C'
第4题:
下列程序在32位linux或unix中的结果是什么?
func(char *str)
{
printf("%d",sizeof(str));
printf("%d",strlen(str));
}
main()
{
char a[]="123456789";
printf("%d",sizeof(a));
func(a);
}
10 4 9
第5题:
下列程序在32位linux或unix中的结果是什么?
func(char *str)
{
printf(" %d",sizeof(str));
printf(" %d",strlen(str));
}
main()
{
char a[]="123456789";
printf(" %d",sizeof(a));
printf(" %d",strlen(a));
func(a);
}
10 9 4 9
第6题:
以下程序: #include<stdio.h> main() {char str[10]; scanf("%s",&str); printf("%s\n",str); } 运行上面的程序,输入字符串how are you,则程序的执行结果是( )。
A.how
B.how are you
C.h
D.howareyou
第7题:
设有char str[10],下列语句正确的是A.scanf("%s",&str); B.printf("%c",str); C.printf("%s",str[0]); D.printf("%s",str);
第8题:
void Test(void){char *str = (char *)
malloc(100); strcpy(str, “hello”); free(str); if(str != NULL) { strcpy(str, “
world”); printf(str);}}请问运行 Test 函数会有什么样的结果?
第9题:
阅读下列程序,当运行函数时,输入asd af aa z67,则输出为
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int fun (char *str)
{ int i,j=0;
for(i=0;str[i]!=′ \0′;i++)
if(str[i]!=′ ′)str[j++]=str[i];
str[j]= ′\0′;
}
main()
{
char str[81];
int n;
printf("Input a string : ");
gets(str);
puts(str);
fun(str);
printf("%s\n",str);
}
A.asdafaaz67
B.asd af aa z67
C.asd
D.z67
第10题:
#include
main()
{ char str[ ]=“The C program”,c;
int i;
for(i=2;(c=str[i])!=‘\0’;i++)
{ switch(c)
{ case ‘g’: ++i; break;
case ‘o’: continue;
default: printf(“%c”,c); continue;
}
printf(“*”);
}
printf(“\n”);
}
第11题:
设有char str〔10〕,下列语句正确的是()
第12题:
int*p;*p=20
char*s=”abcdef”;printf(“%s/n”,s)
charstr[]=”abcd”;str++
charstr[]={‘a’,’b’,’c’};printf(“%s”,str)
第13题:
请补充函数fun(),该函数的功能是:把从主函数中输入的字符串str2接在字符串str1的后面。
例如:str1=“How do”,str2=“you do?”,结果输出: How do you do?
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
define N 40
void fun(char*str1,char *str2)
{
int i=0;
char *pl=str1;
char*p2=str2;
while(【 】)
i++;
for(;【 】;i++)
*(p1+i)=【 】;
*(p1+i)='\0';
}
main()
{
char str1[N],str2[N);
clrscr();
printf("*****Input the string str1 & Str2*****\n");
printf("\nstr1:");
gets(str1);
printf("\nstr2:");
gets(str2);
printf("**The string str1 & str2**\n");
puts(str1);
puts(str2);
fun(str1,str2);
printf("*****The new string *****\n");
puts(str1);
}
第14题:
若有以下说明,则能打印出“Yu”的语句是______。 struct samp { char name[10]; int number; }kk[3]={{"WarBin",1},{"LiYu",2},{"LuHui",3}}; struct samp*str[3]; str[0]=&kk[0];str[1]=&kk[1];str[2]=&kk[2];
A.printf("%s\n",str[1].name[2]);
B.printf("%s\n",str[1]->name+2);
C.printf("%s\n",str[2].name[2]);
D.printf("%s\n",str[2]->name+2);
第15题:
如下程序段#include <stdio.h>#include <ctype.h>#include <conio.h>int fun (char *str){ int i,j=0; for(i=0;str[i]!= ’\0’;i++) if(str[i]!= ’ ’)str[j++]=str[i]; str[j]= ’\0’;}main(){ char str[81]; int n; clrscr(); printf("Input a string : "); gets(str); fun(str); printf("%s\n",str);}当运行程序时,输入asd af aa z67<回车>,则输出是A.asdafaaz67 B.asd af aa z67 C.asd D.z67
第16题:
以下程序: #include<stdio.h> #include<string.h> main() {char str[]="abcd\n\123\xab"; printf("%d",(str)); } 运行后的输出结果是( )。
A.10
B.9
C.7
D.14
第17题:
void setmemory(char **p, int num)
{ *p=(char *) malloc(num);}
void test(void)
{ char *str=NULL;
getmemory(&str,100);
strcpy(str,"hello");
printf(str);
}
运行test函数有什么结果?( )
第18题:
以下程序的输出结果是( )。 char str[15]=”hello!”; printf(“%d\n”,strlen(str));
A.15
B.14
C.7
D.6
第19题:
void GetMemory(char *p){p = (char *)malloc(100);}void Test(void) {char *str
= NULL;GetMemory(str); strcpy(str, "hello world");printf(str);}请问运行 Test 函数
会有什么样的结果?
第20题:
下面的程序各自独立,请问执行下面的四个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);
}
}
第21题:
当运行以下程序时,输入abcd,程序的输出结果是:( )。
insert(char str[])
{int i;
i=strlen(str);
while(i>0)
{str[2*i]=str[i];str[2*i-1]='*';i--;}
printf("%s\n",str);
}
main()
{char str[40];
scanf("%s",str);insert(str);
}
第22题:
用“起泡法”对输入的10个字符排序后按从小到大的次序输出。
#define N 10
char str[N];
main()
{ int i,flag;
for(flag=1;flag==1;)
{ scanf("%s",str);
flag=0;
printf("\n");
}
sort(___(4)___);
for(i=0;i<N;I++)
printf("%c",str[i]);
printf("\n");
}
sort(char str[N])
{ int i,j;
char t;
for(j=1;j<N;J++)
for(i=0;(i<N-J)&&(STR[I]!='\0');I++)
if(str[i]>str[i+1])
{ t=str[i];
____(5)____;
____(6)____;
}
}
第23题:
下面语句正确的是()