下列函数声明和函数定义正确的是()。 int fun1(int, int);void fun2(int x,y)l...] int fun1(int x,y);void fun2(int x,int y)f.... int fun1(int x, int y)void fun2(int x,int y)[...] int fun1(int, int);void fun2(int x, int y)[....
时间: 2023-07-14 14:13:41 浏览: 49
正确的函数声明和函数定义是:
1. int fun1(int, int);
2. void fun2(int x, int y);
3. int fun1(int x, int y);
4. void fun2(int x, int y);
5. int fun1(int x, int y);
6. void fun2(int x, int y);
其中,第1个和第5个是函数声明,第2个、第4个和第6个是函数定义,第3个是函数声明和函数定义同时进行,但是参数列表和返回值类型不一致,所以是错误的。
相关问题
怎样将int main函数改为void fun
将原来的 `int main()` 改为 `void fun()`,并且去掉 `return` 语句即可。例如:
```c++
#include <iostream>
void fun() {
std::cout << "Hello, world!" << std::endl;
}
int main() {
fun();
return 0;
}
```
改为:
```c++
#include <iostream>
void fun() {
std::cout << "Hello, world!" << std::endl;
}
int main() {
fun();
}
```
注意,`main` 函数是程序的入口,它的返回值表示程序的结束状态,一般来说返回值为 0 表示程序正常结束,非 0 表示程序异常结束。因此在将 `main` 函数改为其他函数时,需要注意函数的返回值是否符合要求。在上面的例子中,我们去掉了 `return` 语句,表示程序正常结束。
对于函数声明 void fun(float array[], int *ptr);函数参数 array, ptr 都是指针变量
这个说法是正确的。
在函数声明 void fun(float array[], int *ptr); 中,array 和 ptr 都是形参,也就是函数的参数。在函数调用时,实参会被传递给这些形参,而形参在函数内部被视为变量。由于 array 和 ptr 都是指针类型,因此它们都是指针变量。
在函数内部,可以通过 array 和 ptr 操作实参数组和指针的值,从而实现对实参的修改和操作。需要注意的是,由于 array 和 ptr 都是形参,它们只在函数内部生效,函数结束后将被销毁。因此,如果需要保留对实参的修改,可以使用指针或引用类型的参数,或者通过返回值来传递修改后的值。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)