C语言函数为什么不可以声明默认参数?

为什么C语言函数声明不可以带有默认参数?

我们都知道C++可以在.h文件函数声明中添加默认参数。

比如

void	err_exit(int, const char *, ...) __attribute__((noreturn))


LogOperation(char* config_path = "/mnt/log/log.log");

但是C语言却会报错

#include <stdio.h>
 
int add(int a, int b = 1);

这是为什么呢?

原因很简单,一句话:

C语言没有重载机制,反之对象的编写思想均可以实现带有默认参数的函数 。

猜你喜欢

转载自blog.csdn.net/u012206617/article/details/94030640
今日推荐