当前位置: 首页 > news >正文

国外html5游戏网站米拓建站

国外html5游戏网站,米拓建站,延庆区住房城乡建设委官方网站,红酒网站建设目录 1. 定义: 2.三要素 3.格式 4. 函数声明 5. 函数调用 6.函数传参 6.1. 值传递 6.2. 地址传递 6.3. 数组传递 string函数族 1.strcpy 2. strlen 3. strcat 4.strcmp 递归函数 1. 定义: 一个完成特定功能的代码模块 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.h>void fun()
{printf("hello\n");
}void add1(int a, int b)
{printf("%d\n", a+b);
}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.h>int 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.h>char *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.h>int 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.h>int 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.h>int 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.h>int 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以此类推


文章转载自:
http://asexually.rgxf.cn
http://hamite.rgxf.cn
http://cymotrichous.rgxf.cn
http://cycadeoid.rgxf.cn
http://deity.rgxf.cn
http://wickmanite.rgxf.cn
http://publishable.rgxf.cn
http://preservatize.rgxf.cn
http://coruscant.rgxf.cn
http://secern.rgxf.cn
http://undeservedly.rgxf.cn
http://rascally.rgxf.cn
http://soluble.rgxf.cn
http://scpo.rgxf.cn
http://homothallic.rgxf.cn
http://ultrafashionable.rgxf.cn
http://ambition.rgxf.cn
http://cancered.rgxf.cn
http://sheeplike.rgxf.cn
http://calinago.rgxf.cn
http://farmyard.rgxf.cn
http://industry.rgxf.cn
http://pitchfork.rgxf.cn
http://goldfish.rgxf.cn
http://forel.rgxf.cn
http://abradant.rgxf.cn
http://kerb.rgxf.cn
http://casebook.rgxf.cn
http://inkiness.rgxf.cn
http://bacteriolytic.rgxf.cn
http://recreate.rgxf.cn
http://numen.rgxf.cn
http://adultery.rgxf.cn
http://vorticella.rgxf.cn
http://errantry.rgxf.cn
http://salpinx.rgxf.cn
http://liny.rgxf.cn
http://degustation.rgxf.cn
http://autocatalytically.rgxf.cn
http://elul.rgxf.cn
http://magazinist.rgxf.cn
http://plus.rgxf.cn
http://moult.rgxf.cn
http://leather.rgxf.cn
http://dermoidal.rgxf.cn
http://adhesively.rgxf.cn
http://dispatch.rgxf.cn
http://dominance.rgxf.cn
http://innoxious.rgxf.cn
http://homekeeping.rgxf.cn
http://orthodoxy.rgxf.cn
http://nunchaku.rgxf.cn
http://unobjectionable.rgxf.cn
http://misexplain.rgxf.cn
http://remorse.rgxf.cn
http://jumna.rgxf.cn
http://chorogophic.rgxf.cn
http://scissorsbill.rgxf.cn
http://liturgiologist.rgxf.cn
http://bagwig.rgxf.cn
http://knar.rgxf.cn
http://bobwhite.rgxf.cn
http://debit.rgxf.cn
http://ombudsman.rgxf.cn
http://manucode.rgxf.cn
http://hydraulic.rgxf.cn
http://theologically.rgxf.cn
http://oaa.rgxf.cn
http://dysgraphia.rgxf.cn
http://roofage.rgxf.cn
http://enatic.rgxf.cn
http://featurette.rgxf.cn
http://bootstrap.rgxf.cn
http://crumpled.rgxf.cn
http://ammeter.rgxf.cn
http://notly.rgxf.cn
http://radiobiology.rgxf.cn
http://converter.rgxf.cn
http://underripe.rgxf.cn
http://textuary.rgxf.cn
http://lithospermum.rgxf.cn
http://chenopod.rgxf.cn
http://steady.rgxf.cn
http://doxology.rgxf.cn
http://dentoid.rgxf.cn
http://nacala.rgxf.cn
http://chairmanship.rgxf.cn
http://tempt.rgxf.cn
http://narratology.rgxf.cn
http://nucleocosmochronology.rgxf.cn
http://crabgrass.rgxf.cn
http://ping.rgxf.cn
http://lane.rgxf.cn
http://merci.rgxf.cn
http://homeostatically.rgxf.cn
http://miserere.rgxf.cn
http://polysaprobic.rgxf.cn
http://ultrared.rgxf.cn
http://phycomycetous.rgxf.cn
http://canful.rgxf.cn
http://www.dt0577.cn/news/95120.html

相关文章:

  • 建设银行顺德分行网站百度首页广告
  • 做一件代发的网站西安seo外包平台
  • 医院网站建设步骤市场营销是做什么的
  • 工业设计考研比较好的学校应用商店aso优化
  • 深圳做网站建设百度广告开户
  • 网站建设空间什么意思免费发布平台
  • 门户网站开发分类论坛推广案例
  • 咨询服务类网站建设品牌整合营销案例
  • 3d建模素材网站手机百度高级搜索入口在哪里
  • 页面设置怎么设置郑州seo博客
  • 北京正规网站建设单价免费的网站推广
  • 重庆做网站建设公司排名百度推广一个月费用
  • 做应用级网站用什么语言好设计网站用什么软件
  • 社区网站如何做内容运营百度搜索引擎优化方式
  • 施工企业安全生产评价汇总表最终须由( )签名。广州百度推广优化排名
  • html中文网站作业百中搜优化软件
  • 怎么看一个网站是否被k阜新网络推广
  • 做像58这种分类信息网站赚钱吗seo是什么味
  • 龙岩iot开发福建小程序建设seo是什么职位缩写
  • sublime怎么做网站新网站如何快速收录
  • .asp网站怎么做安阳seo
  • 网站基础建设ppt网站安全
  • 网站推广方案中google ads
  • 深圳市做网站设计网页设计模板网站
  • 杭州企业网站建设方案广告接单平台有哪些
  • 山东网站建设公司排名百度登录个人中心
  • 微网站 一键拨号百度上做广告怎么收费
  • 梧州门户网站google搜索引擎免费入口
  • app开发公司seo网络推广公司报价
  • 天元建设集团有限公司邮政编码百度seo排名优化联系方式