dengzhekaihua

c++的函数需要声明才能再写他的定义,声明可以写多次,如果执行在main之前可以不写,全写不会犯错,现在看好像c++的函数定义里没有out,也没有变量的public和private(后面有再改)

声明:int max(int a,int b); **写到.h后缀的头文件中**
int main()
{
int a; int b;
max(a,b)
}
定义:**写到.cpp后缀的源文件中**
int max(int a,int b)
{
return a;
}
在源文件中,要在上面写头文件的关联
#include <iostream>
using namespace std;
#include"头文件名.h"

在头文件中,上面要写
#include <iostream>
using namespace std;

指针

简单来说,指针就是个地址

如何定义一个指针

int a=10;
指针定义的语法:数据类型 *指针变量名;
int * point;
让指针记录变量a的地址
point=&a;(&是取址符号)

使用指针 通过解引用的方式来找到指针指向的内存

* point(指针前加 * 代表指向p内存的一个数据)
\int *p=&a; 定义一个指向a变量的指针p

相关文章:

  • 2021-05-10
  • 2021-04-05
  • 2021-12-22
  • 2022-12-23
  • 2022-01-13
  • 2021-12-15
  • 2022-01-10
  • 2021-06-10
猜你喜欢
  • 2021-10-30
  • 2021-10-26
  • 2021-08-04
  • 2021-12-02
  • 2022-01-08
  • 2022-01-07
  • 2021-09-10
相关资源
相似解决方案