#include <stdio.h> #include <iostream> using namespace std; f() { static int c = 3; c++; return c; } //计算字符串长度 int fu(char* s) { char *p = s; while (*p != '/0') { p++; } return (p - s); } //递归 void fun(char *s) { if (*s) { fun(++s); printf("%s/n", --s); } } //从字符串中删除小于字符‘n’的字符 void fun1(char s1[]) { int i, j; for (i=j=0; *(s1 + i) != '/0'; i++) { if (*(s1+i) < 'n') { *(s1 + j) = *(s1 + i); //如果j != i, 表示第j个元素为大于‘n’的字符,则把第i个元素覆盖到j位置元素 j++; } } *(s1 + j) = '/0'; } void fun2(int b[]) { int i = 0; while (b[i] <= 10) //当元素大于10时,则循环退出 { b[i] += 2; i++; } } int main() { static char str[] = "123"; fun(str); int i, k; char str1[] = "morning", *pstr; pstr = str1; fun1(pstr); cout << pstr << endl; int (*p)(); //define funtion pointer p = f; for (i = 0; i < 2; i++) { k = p(); } printf("k=%d/n", k); int a[] = { 1, 5, 10, 9, 13, 7}; fun2(a + 1); for (i = 0; i < 6; i++) { printf("a[%d] =%d/n", i, a[i]); } return 0; } 运行结果: 3 23 123 mig k=5 a[0]=1 a[1]=7 a[2]=12 a[3]=11 a[4]=13 a[5]=9