1 #include<stdio.h>
2 #include<math.h>
3
4 extern void addnumber(double a,double b); //在这里告诉编译器,这个函数是另外一个文件中的
5 extern void addnumberb(double &a,double &b); //.cpp 文件中才能允许使用引用
6 int main()
7 {
8 printf("helloworld\n");
9 double a=exp(2);
10 double b=exp(3);
11 printf("a=%f;b=%f\n",a,b);
12 addnumber(a,b);//传入的值
13
14 addnumberb(a,b); //在这个函数中,传入a,b 的引用,即使址传递,所以,在这个函数内部发生的变化,也会随着函数执行结束带到主函数中
15 return 0;
16 }
![]()
{
"tasks": [
{
"type": "process",
"label": "hello1",
//"command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe",
"command":"gcc",
"args": [
"-g",
"${workspaceFolder}\\hello.cpp", //这里要给出全路径位置
"${workspaceFolder}\\func.cpp",
"-o",
"hello.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "调试器生成的任务。"
},
{
"type": "shell", // cppbuild 不可以
"label": "command",
"command": "dir", //
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "调试器生成的任务。"
},
{
// "type": "",
"label": "hello",
"dependsOn":[
"hello1",
"command"
],
"dependsOrder": "sequence"
},
],
"version": "2.0.0"
}
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\hello.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "hello"
}
]
}
#include<stdio.h>
extern void addnumber(double a,double b) //这里告诉编译器,这个函数可以被其他文件引用
{
double c;
c=a;
a=b;
b=c;
printf("this is a extern func:%f+%f=%f\n",a,b,a+b);
}
extern void addnumberb(double &a,double &b) //这里告诉编译器,这个函数可以被其他文件引用
{
double c;
c=a;
a=b;
b=c;
printf("this is a extern func:%f+%f=%f\n",a,b,a+b);
}