Linux 下C语言编程题!

Linux 下C语言编程题!,第1张

1.#include<stdio.h>

#include<string.h>

#include<malloc.h>

main()

{ char *s,*h,*tint l

s=(char*)malloc(20*sizeof(char))

printf("input a string:")

scanf("%s",s)

l=strlen(s)/*求字符串长度赋给l*/

h=st=s+l-1/*h指针指向第一个字符,t指向最后一个*/

for(h<th++,t--) /*从头尾向中比较*/

{if((*h)!=(*t)){printf("not symmetric")break} /*发现不同的字符,显示不对称,并结束比较*/

}if(h>=t)printf("symmetric")/*如果比较完了,则显示对称*/

getch()

}

2.#include<stdio.h>

#include<string.h>

#include<malloc.h>

main()

{ char *s,*p,*q

s=(char*)malloc(20*sizeof(char))

printf("input string:")

scanf("%s",s)

p=s

while(*p)

{if(*p=='a'||*p=='e'||*p=='i'||*p=='o'

||*p=='u')

{q=p/*让q指针和q指针指向同一个字符*/

while(*q)

{*q=*(q+1)q++} /*将当前字符后面的字符前移,相当于把p指着的当前字符删除*/

p--}

p++}

printf("%s",s)

getch()

}

3.#include<stdio.h>

#include<string.h>

main()

{ int a,i=0,s=0char b[52],c[100],t

for(t='A't<='Z't++)

b[i++]=t

for(t='a't<='z't++)

b[i++]=t

for(i=0i<52i++)

printf("%c",b[i])/*将52个大小写字母存入数组b中*/

srand(time(NULL))/*使每次随机产生的数不同*/

for(i=0i<100i++) /*循环100次,产生100个随机字母*/

{ a=rand()%51/*每次从0到51中产生一个随机数,从而从b〔0〕到b〔51〕中选出一个字母*/

c[i]=b[a]/*每次产生的随机字母存入数组c中*/

if(b[a]=='a'||b[a]=='e'||b[a]=='i'||

b[a]=='o'||b[a]=='u'||b[a]=='A'||

b[a]=='E'||b[a]=='I'||b[a]=='O'||b[a]

=='U')s++/*当是元音字母时,用s来统计个数*/

}

printf("\n")

for(i=0i<100i++)printf("%c ",c[i])

printf("\ns:%d",s)

getch()

}

2.某32位系统下, C++程序,请计算sizeof 的值(5分).char str[] = “ http://www.ibegroup.com/”char *p = str int n = 10请计算sizeof (str ) = ?(1)sizeof ( p ) = ?(2)sizeof ( n ) = ?(3)void Foo ( char str[100]){请计算sizeof( str ) = ?(4)}void *p = malloc( 100 )请计算sizeof ( p ) = ?(5)2>Void GetMemory(char **p, int num){*p = (char *)malloc(num)}void Test(void){char *str = NULLGetMemory(&str, 100)strcpy(str, "hello")printf(str)}请问运行Test 函数会有什么样的结果?3>int i=10, j=10, k=3k*=i+jk最后的值是4>以下是求一个数的平方的程序,请找出错误:#define SQUARE(a)((a)*(a))int a=5int bb=SQUARE(a++)4>C/C++编译器中虚表是如何完成的?5>.对于一个频繁使用的短小函数,在C语言中应用什么实现,在C++中应用什么实现?6>unsigned char *p1 unsigned long *p2 p1=(unsigned char *)0x801000 p2=(unsigned long *)0x810000 请问p1+5= p2+5=


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8503043.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-17
下一篇2023-04-17

发表评论

登录后才能评论

评论列表(0条)

    保存