1.终端输入一个数,递归输出它的每一位,例:123 输出:123,void为返回值。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void s(int n)
{
if(n>9)
s (n/10);
printf("%d",n%10);
}int main(int argc, const char *argv[])
{
int num;
scanf("%d", &num);
s(num);
putchar(10);
}
2.*p++和++*p的区别
*p++是先解引用p,再对p进行自增,++*p是先解引用p,再对p解引用的结果自增。
3.有以下定义,说明哪些量可以改变哪些不可以改变。
const char *p:p指向的内容不可更改,p可以更改。
const (char *) p:p指向的内容不可更改,p可以更改。
char * const p:p指向的内容可更改,p不可以更改。
const char * const p:p指向的内容不可更改,p也不可更改。
char const *p:p指向的内容不可更改,p可以更改。
(char*)const p:p指向的内容可更改,p不可更改。
char const* const p:p指向的内容不可更改,p也不可更改。
4.终端输入字符串,使用指针完成删空格操作并逆置。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void skg(char *p)
{
int i = 0;
int j = 0;
while(*(p+i))
{
if(*(p+i)!=' ')
{
*(p+j)=*(p+i);
j++;
}
i++;
}
*(p+j)=*(p+i);
}void nizhi(char *p1)
{
int len = strlen(p1);
char tmp = *p1;
*p1 = *(p1 + len - 1);
*(p1 + len - 1) = '\0';
if(strlen(p1+1) > 1 )
nizhi(p1 + 1);
*(p1 + len - 1) = tmp;
}
int main(int argc, const char *argv[])
{
char s[32];
gets(s);
skg(s);
puts(s);
nizhi(s);
puts(s);}