day13.1
谁能横刀立马,唯我飞牛大将军!
涵盖知识点:
函数的嵌套调用和链式访问
函数的声明与定义
多文件的使用
下面是day13所学的知识点:
1.char str[10] = {…}; //输入字符串比较特殊
scanf("%s",str);
这里的char str[]就代表str的地址,所以str前无&
2.函数的嵌套调用和链式访问
嵌套调用
#include <stdio.h>
void new_line()
{
printf("hehe\n");
}
void three_line()
{
int i = 0;
for(i=0; i<3; i++)
{
new_line();
}
}
int main()
{
three_line();
return 0;
}
链式访问
把一个函数的返回值作为另一个函数的参数
#include <stdio.h>
#include <string.h>
int main()
{
char arr[20] = "hello";
int ret = strlen(strcat(arr,"bit"));//这里介绍一下strlen函数
求字符串长度
printf("%d\n", ret);
return 0; }
#include <stdio.h>
int main()
{
printf("%d", printf("%d", printf("%d", 43)));
//结果是啥?
return 0; }
这里就是把 printf("%d", 43)的返回值作为另外printf函数的参数了。
3.函数的声明与定义
函数声明:
1.告诉编译器有一个函数叫什么,参数是什么,返回类型是什么。但是具体是不是存在,无关紧要。
2. 函数的声明一般出现在函数的使用之前。要满足先声明后使用。
3. 函数的声明一般要放在头文件中的。
函数定义:
函数的定义是指函数的具体实现,交代函数的功能实现
test.h的内容 放置函数的声明
//预处理符,防止头文件被重复包含
#ifndef __TEST_H__
#define __TEST_H__
//函数的声明
int Add(int x, int y);
#endif //__TEST_H__
test.c的内容 放置函数的实现
#include "test.h"
//函数Add的实现
int Add(int x, int y) {
return x+y; }