iis默认网站怎么设置,江苏seo和网络推广,每个网站都有服务器吗,wordpress主题栏是什么意思目录
1. 定义#xff1a;
2.三要素
3.格式
4. 函数声明
5. 函数调用
6.函数传参
6.1. 值传递
6.2. 地址传递
6.3. 数组传递
string函数族
1.strcpy
2. strlen
3. strcat
4.strcmp
递归函数 1. 定义#xff1a;
一个完成特定功能的代码模块
2.三要素
功能、…
目录
1. 定义
2.三要素
3.格式
4. 函数声明
5. 函数调用
6.函数传参
6.1. 值传递
6.2. 地址传递
6.3. 数组传递
string函数族
1.strcpy
2. strlen
3. strcat
4.strcmp
递归函数 1. 定义
一个完成特定功能的代码模块
2.三要素
功能、参数、返回值
3.格式
存储类型 数据类型 函数名参数列表
{
函数体
return 函数返回值
}
1) 没有参数参数列表可以省略也可以使用 void
2) 没有返回值数据类型为void函数内部没有return
3) 有返回值要根据返回值的数据类型定义函数的数据类型
4) 定义子函数时可以直接定义在主函数上面如果定义在主函数下面需要提前声明函数
4. 函数声明
数据类型函数名(参数列表);//形参
5. 函数调用
1) 没有返回值直接调用函数名(参数列表); // 实参 2) 有返回值
如果需要接收返回值就要定义一个与返回值数据类型相同的变量接收
如果不需要接收返回值就要直接调用函数
简单的使用
#include stdio.hvoid fun()
{printf(hello\n);
}void add1(int a, int b)
{printf(%d\n, ab);
}int add2(int a, int b)
{return a b;
}int sub(int a, int b);int main(int argc, char const *argv[])
{int a 2, b 3;fun();add1(1, 2);int num add2(a, b);printf(%d\n, num);int sum sub(5, 4);printf(%d\n, sum);printf(%d\n, sub(5,4));return 0;
}int sub(int a, int b)
{return a-b;
}
练习1编写一个函数函数的2个参数第一个是一个字符第二个是一个char *返回字符串中该字符的个数。 练习2编程实现strlen函数的功能strlen计算字符串实际长度不包含’\0’
6.函数传参
6.1. 值传递
单向传递将实参传递给形参使用改变形参实参不会受到影响
#include stdio.h
int fun(int a, int b)
{a;b;return a b;
}int main(int argc, char const *argv[])
{int a 3, b 4;int num fun(a, b);printf(%d %d %d\n, a, b, num);return 0;
}
6.2. 地址传递
双向传递在函数中修改形参实参随之变化
#include stdio.hint fun(int *a, int *b)
{*a *a *b;*b *b 2;return *a *b;
}int main(int argc, char const *argv[])
{int a 3, b 4;// 因为你是拿到了地址对地址进行赋值并不是拿到值int num fun(a, b);printf(%d %d %d\n, a, b, num);return 0;
}
6.3. 数组传递
和地址传递一样参数中存在数组的定义它也会认为是指针
#include stdio.hchar *fun(char str[32])
{str hello;printf(%d\n, sizeof(str)); // 4return str;
}int main(int argc, char const *argv[])
{char *ch fun(abc);printf(%s\n, ch); return 0;
}
补充
// s 在栈区空间开辟4字节空间存放字符串常量 hello 的首地址
char *s hello;// 在栈区开辟 32 个字节的空间存放 hello 字符串
char str[32] hello; string函数族
1.strcpy
#include string.h
char *strcpy(char *dest, const char *src);
功能实现字符串的复制
参数dest目标字符串首地址
src源字符串首地址
返回值目标字符串首地址
#include stdio.h
#include string.hint main()
{char str[32];char ch[32] world;strcpy(str, ch);printf(%s\n, str);return 0;
}
复制包括\0
char *strncpy(char *dest, const char *src, size_t n);
功能实现字符串复制
参数dest目标字符串首地址
src源字符串首地址
n字符的个数
返回值目标字符串首地址
#include stdio.h
#include string.hint main()
{char str[32] hello;char ch[32] world;strncpy(str, ch, 2);printf(%s\n, str);return 0;
}
2. strlen
#include string.h
size_t strlen(const char *s);
功能计算字符串的实际长度
参数s字符串的首地址
返回值实际长度
3. strcat
#include string.h
char *strcat(char *dest, const char *src);
功能用于字符串拼接
参数dest目标字符串首地址
src源字符串首地址
返回值目标字符串首地址
#include stdio.h
#include string.hint main()
{char str[32] hello;char ch[32] world;strcat(str, ch);printf(%s\n, str);return 0;
}
char *strncat(char *dest, const char *src, size_t n);//拼接str的前n个内容
功能实现字符串拼接
参数dest目标字符串首地址
src源字符串首地址
n字符的个数
返回值目标字符串首地址
4.strcmp
#include string.h
int strcmp(const char *s1, const char *s2);
功能用于字符串比较
参数s1、s2字符串的首地址
返回值
从字符串首个字符开始比较字符ASCII的大小如果相等继续向后比较
1 s1 s2
0 s1 s2
-1 s1 s2
#include stdio.h
#include string.hint main()
{char s1[] hello;char s2[] worldworld;char *s3 ikun;char *s4 nihao;char *s5 helloworld;char *s6 helloworld;// int ret strcmp(s1, s2); // -1// int ret strcmp(s1, s3); // -1// int ret strcmp(s2, s3); // 1// int ret strcmp(s2, s4); // 1int ret strcmp(s5, s6); // 0printf(%d\n, ret);return 0;
}
int strncmp(const char *s1, const char *s2, size_t n);比较两个字符串前n个字符的大小
递归函数
1. 定义自己调用自己
2. 执行过程分为两个阶段
a. 递推阶段从原问题出发按递推公式从未知到已知最终达成递归的终止条件
b. 回归阶段按递推的终止条件求出结果逆向逐步带入递归公式回到原问题求解
3. 递归的两个必要条件
a. 存在限制条件当满足这个限制条件的时候递推便不再继续
b. 每次递推之后会越来越接近这个限制条件
例子求 5-1的阶乘 例子2打印一个数的每一位
接收一个整型值按照顺序打印它的每一位
示例1234
输出1,2, 3, 4;
思路递归就是把大事化小函数自己调用自己
按照顺序打印它的每一位我们就用 1234 % 10就会等于4这样就打印出一个4那怎么打印其他的数123 怎么来呢1234 / 10 123再继续123 % 10 就等于3以此类推